Hi,
I have 2 classes, one annotated with JPA annotations and another using hibernate xml configuration (hbm.xml). I am using Spring's LocalContainerEntityManagerFactoryBean to create the EntityManager. The mapping from annotated class to hbm class is working fine. But when I have a mapping from hbm class to annotated class it doesn't work (for example a one-to-many mapping).
I have 2 classes. One called Employee which is using JPA annotations. Another is called Organization which is mapped using Organization.hbm.xml file.
Below is the log snippet.
Exception:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [jpahbm-context.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: Employee
Caused by: org.hibernate.MappingException: Association references unmapped class: Employee
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPa ss(HbmBinder.java:2380)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.s econdPass(HbmBinder.java:2662)
at org.hibernate.cfg.CollectionSecondPass.doSecondPas s(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile( Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPa ssCompile(AnnotationConfiguration.java:316)
at org.hibernate.cfg.Configuration.buildMappings(Conf iguration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings( Ejb3Configuration.java:1269)
at org.hibernate.ejb.EventListenerConfigurator.config ure(EventListenerConfigurator.java:150)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3 Configuration.java:888)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3 Configuration.java:416)
Log snippet
DEBUG main org.hibernate.ejb.Ejb3Configuration - Processing PersistenceUnitInfo [
name: jpahbm
persistence provider classname: org.hibernate.ejb.HibernatePersistence
classloader: org.springframework.test.jpa.OrmXmlOverridingShado wingClassLoader@17943a4
Temporary classloader: org.springframework.instrument.classloading.Resour ceOverridingShadowingClassLoader@faa550
excludeUnlistedClasses: true
JTA datasource: null
Non JTA datasource: org.springframework.jdbc.datasource.DriverManagerD ataSource@17b6643
Transaction type: RESOURCE_LOCAL
PU root URL: file:/C:/jpa-hbm/target/classes/
Jar files URLs []
Managed classes names [
com.jpahbm.model.Employee]
Mapping files names [
Organization.hbm.xml]
Properties [
hibernate.archive.autodetection: none]
DEBUG main org.hibernate.ejb.Ejb3Configuration - Detect class: false; detect hbm: false
DEBUG main org.hibernate.ejb.Ejb3Configuration - Detect class: false; detect hbm: false
DEBUG main org.hibernate.util.DTDEntityResolver - trying to resolve system-id [http://hibernate.sourceforge.net/hib...pping-3.0.dtd]
DEBUG main org.hibernate.util.DTDEntityResolver - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
DEBUG main org.hibernate.util.DTDEntityResolver - located [http://hibernate.sourceforge.net/hib...pping-3.0.dtd] in classpath
INFO main org.hibernate.cfg.Configuration - Reading mappings from resource : Organization.hbm.xml
DEBUG main org.hibernate.util.DTDEntityResolver - trying to resolve system-id [http://hibernate.sourceforge.net/hib...pping-3.0.dtd]
DEBUG main org.hibernate.util.DTDEntityResolver - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
DEBUG main org.hibernate.util.DTDEntityResolver - located [http://hibernate.sourceforge.net/hib...pping-3.0.dtd] in classpath
DEBUG main org.hibernate.cfg.AnnotationConfiguration - Execute first pass mapping processing
DEBUG main org.hibernate.cfg.AnnotationConfiguration - Process hbm files
INFO main org.hibernate.cfg.HbmBinder - Mapping class: com.jpahbm.model.Organization -> organization
DEBUG main org.hibernate.cfg.HbmBinder - Mapped property: orgId -> id
DEBUG main org.hibernate.cfg.HbmBinder - Mapped property: orgName -> name
DEBUG main org.hibernate.cfg.HbmBinder - Mapped property: employees
DEBUG main org.hibernate.cfg.AnnotationConfiguration - Process annotated classes
INFO main org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.jpahbm.model.Employee
DEBUG main org.hibernate.cfg.Ejb3Column - Binding column DTYPE unique false
DEBUG main org.hibernate.cfg.annotations.EntityBinder - Import with entity name=Employee
INFO main org.hibernate.cfg.annotations.EntityBinder - Bind entity com.jpahbm.model.Employee on table employee
DEBUG main org.hibernate.cfg.AnnotationBinder - Processing com.jpahbm.model.Employee property annotation
DEBUG main org.hibernate.cfg.AnnotationBinder - Processing com.jpahbm.model.Employee field annotation
DEBUG main org.hibernate.cfg.AnnotationBinder - Processing annotations of com.jpahbm.model.Employee.id
DEBUG main org.hibernate.cfg.Ejb3Column - Binding column id unique false
DEBUG main org.hibernate.cfg.AnnotationBinder - id is an id
DEBUG main org.hibernate.cfg.annotations.SimpleValueBinder - building SimpleValue for id
DEBUG main org.hibernate.cfg.annotations.PropertyBinder - Building property id
DEBUG main org.hibernate.cfg.AnnotationBinder - Bind @Id on id
DEBUG main org.hibernate.cfg.AnnotationBinder - Processing annotations of com.jpahbm.model.Employee.firstName
DEBUG main org.hibernate.cfg.Ejb3Column - Binding column first_name unique false
DEBUG main org.hibernate.cfg.annotations.PropertyBinder - binding property firstName with lazy=false
DEBUG main org.hibernate.cfg.annotations.SimpleValueBinder - building SimpleValue for firstName
DEBUG main org.hibernate.cfg.annotations.PropertyBinder - Building property firstName
DEBUG main org.hibernate.cfg.AnnotationBinder - Processing annotations of com.jpahbm.model.Employee.lastName
DEBUG main org.hibernate.cfg.Ejb3Column - Binding column last_name unique false
DEBUG main org.hibernate.cfg.annotations.PropertyBinder - binding property lastName with lazy=false
DEBUG main org.hibernate.cfg.annotations.SimpleValueBinder - building SimpleValue for lastName
DEBUG main org.hibernate.cfg.annotations.PropertyBinder - Building property lastName
DEBUG main org.hibernate.cfg.AnnotationBinder - Processing annotations of com.jpahbm.model.Employee.location
DEBUG main org.hibernate.cfg.Ejb3Column - Binding column location unique false
DEBUG main org.hibernate.cfg.annotations.PropertyBinder - binding property location with lazy=false
DEBUG main org.hibernate.cfg.annotations.SimpleValueBinder - building SimpleValue for location
DEBUG main org.hibernate.cfg.annotations.PropertyBinder - Building property location
DEBUG main org.hibernate.cfg.AnnotationBinder - Processing annotations of com.jpahbm.model.Employee.organization
DEBUG main org.hibernate.cfg.Ejb3Column - Binding column organization_id unique false
DEBUG main org.hibernate.cfg.Ejb3Column - Binding column organization unique false
DEBUG main org.hibernate.cfg.annotations.PropertyBinder - Building property organization
DEBUG main org.hibernate.cfg.AnnotationConfiguration - processing manytoone fk mappings
DEBUG main org.hibernate.cfg.Configuration - processing extends queue
DEBUG main org.hibernate.cfg.Configuration - processing collection mappings
DEBUG main org.hibernate.cfg.CollectionSecondPass - Second pass for collection: com.jpahbm.model.Organization.employees
INFO main org.springframework.beans.factory.support.DefaultL istableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@84ce7a: defining beans [org.springframework.dao.annotation.PersistenceExce ptionTranslationPostProcessor,org.springframework. orm.jpa.support.PersistenceAnnotationBeanPostProce ssor,dataSource,hibernateJpaVendorAdapter,entityMa nagerFactory,transactionManager,org.springframewor k.aop.config.internalAutoProxyCreator,org.springfr amework.transaction.interceptor.TransactionAttribu teSourceAdvisor,organizationDao,employeeDao]; root of factory hierarchy
|