-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem mixing hbm and JPA annotated classes
PostPosted: Wed Jan 16, 2008 2:48 am 
Newbie

Joined: Wed Jan 16, 2008 2:43 am
Posts: 4
Location: San Diego
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 8:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
it might not be fully qualified or the default package is wrong

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 1:12 pm 
Newbie

Joined: Wed Jan 16, 2008 2:43 am
Posts: 4
Location: San Diego
Hi Emmanuel,

Here is my Organization.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.jpahbm.model.Organization"
table="organization">
<id name="orgId"
column="id"
unsaved-value="null">
<generator class="increment"/>
</id>
<property name="orgName"
column="name"
not-null="true"/>
<set name="employees"
inverse="true"
cascade="save-update">
<key column="organization_id"/>
<one-to-many class="Employee"/>
</set>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Thank you
PostPosted: Wed Jan 16, 2008 1:28 pm 
Newbie

Joined: Wed Jan 16, 2008 2:43 am
Posts: 4
Location: San Diego
Hi Emmanuel,

You are absolutely right from the hbm.xml file I posted earlier. I forgot to qualify the Employee class with the package in the one-to-many mapping.

Thank you very much for your suggestion.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.