Exception when trying to saving entity getting org.hibernate.MappingException: Unknown entity

Application Name: OpenMrs

Question:

Created a new module by using Maven Archetype

mvn module-wizard:generate -s settings.xml                                                                                                                                                                                                                                                                                                                 
Group ID:  org.openmrs.module: :  
Artifact ID:  basicexample: : department
Version:  1.0-SNAPSHOT: :  
Module name:  Basic Example: : department  
Module description:  Helps to start writing OpenMRS modules: :  
Module author:  xyz: :  
OpenMRS version to depend on:  1.8.2: :  
Do you want to add an admin page link: (y/n)  y: : y  
Do you want to add a service layer: (y/n)  y: : y  
Service name:  department: :  
Model object name:  department: :  
Do you want to add another module to depend on: (y/n)  n: : n  
Ready to create a module. Are the above values correct: (y/n) : y

followed the below url to add a new field to your data model http://en.flossmanuals.net/openmrs-developers-guide/hello-world-module/ but when tries to persist using api

sessionFactory.getCurrentSession().save(department);

i am getting a exception getting org.hibernate.MappingException: Unknown entity: org.openmrs.module.department.Department

Thanks the issue was fixed .hbm.xml was not scanned under class path.

Hi, Could you let me know how (where) you fixed this ?

This might help someone in the future. I was trying to use data integrity module version 2.3 on OpenMRS version 1.11.6. It turns out the way the hibernate mapping files were declared back then was different from the way the module parser expects in the recent versions, 1.11.6 being the case in point here. So the problem is the mapping files were not found resulting in the entities not being mapped which the exception being thrown clearly reports.

Below is how mapping files were defined in version 2.3 of the module in question.

 <!-- Hibernate Mapping -->
 	<mappingFiles>
 		<mapping resource="DataIntegrityCheck.hbm.xml" />
 		<mapping resource="DataIntegrityColumn.hbm.xml" />
 		<mapping resource="DataIntegrityResult.hbm.xml" />
		<mapping resource="DataIntegrityRun.hbm.xml" />
 	</mappingFiles>
     <!-- /Hibernate Mapping -->

Below is how the 1.11.6 expects it to be.

<!-- Hibernate Mapping -->
	<mappingFiles>
		DataIntegrityCheck.hbm.xml
		DataIntegrityColumn.hbm.xml
		DataIntegrityResult.hbm.xml
		DataIntegrityRun.hbm.xml
	</mappingFiles>
<!-- /Hibernate Mapping -->

Fortunately for me I just needed to upgrade to version 3.0 which is already available.

Note There is a later version of the module which works with the reference application which we can not use because we are still using legacy UI.