-->
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.  [ 7 posts ] 
Author Message
 Post subject: One-to-many relationship issue
PostPosted: Thu Apr 01, 2004 2:26 pm 
Newbie

Joined: Thu Apr 01, 2004 2:19 pm
Posts: 14
I am using Hibernate version 2.1

I have a one-to-many relationship configured. When I run my code, it gives me the following error:

12:13:11,148 INFO Configuration:595 - processing one-to-many association mappin
gs
Exception in thread "main" net.sf.hibernate.MappingException: Association refere
nces unmapped class: com.pepsi.compensation.PlanComponent
at net.sf.hibernate.cfg.Binder.bindCollectionSecondPass(Binder.java:1148
)
at net.sf.hibernate.cfg.Binder$CollectionSecondPass.secondPass(Binder.ja
va:1352)
at net.sf.hibernate.cfg.Binder$SecondPass.doSecondPass(Binder.java:1328)

at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.ja
va:600)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.
java:743)
at com.pepsi.compensation.PlanAccessor.configure(PlanAccessor.java:14)
at com.pepsi.compensation.PlanAccessor.main(PlanAccessor.java:103)


Can anyone help me?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 2:50 pm 
Newbie

Joined: Fri Oct 31, 2003 9:17 am
Posts: 10
Location: USA
Can you post your mapping file(s)?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 3:16 pm 
Newbie

Joined: Thu Apr 01, 2004 2:19 pm
Posts: 14
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.pepsi.compensation.Plan" table="PLAN">
<id name="id" type="string" unsaved-value="null">
<column name="ID" sql-type="varchar2(255)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="name">
<column name="NAME" sql-type="varchar2(50)" not-null="true"/>
</property>
<property name="desc">
<column name="DESCRIPTION" sql-type="varchar2(255)" not-null="true"/>
</property>
<set name="componentSet" table="PLAN_COMPONENT" inverse="true" cascade="all">
<key column="PLAN_ID"/>
<one-to-many class="com.pepsi.compensation.PlanComponent"/>
</set>
</class>
</hibernate-mapping>




<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.pepsi.compensation.Component" table="COMPONENT">
<id name="id" type="string" unsaved-value="null">
<column name="ID" sql-type="varchar2(255)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="name">
<column name="NAME" sql-type="varchar2(50)" not-null="true"/>
</property>
<property name="desc">
<column name="DESCRIPTION" sql-type="varchar2(255)" not-null="true"/>
</property>
</class>
</hibernate-mapping>





<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.pepsi.compensation.PlanComponent" table="PLAN_COMPONENT">
<id name="id" type="string" unsaved-value="null">
<column name="ID" sql-type="varchar2(255)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="planID" insert="false" update="false">
<column name="PLAN_ID" sql-type="varchar2(255)" not-null="true"/>
</property>
<property name="componentID" insert="false" update="false">
<column name="COMPONENT_ID" sql-type="varchar2(255)" not-null="true"/>
</property>
<many-to-one name="plan" class="com.pepsi.compensation.Plan" column="PLAN_ID"/>
<many-to-one name="component" class="com.pepsi.compensation.Component"
cascade="save-update" column="COMPONENT_ID"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 3:26 pm 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
Have you made sure that the class com.pepsi.compensation.PlanComponent is known to the hibernate configuration (i.e. a mapping element for this class appears in hibernate.cfg.xml, or another similar registration mechanism is used)?

Other than a type-o, the problem described above is the most common cause of this type of error that I've seen.

Hope this helps.

_________________
Mike Davison


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 3:31 pm 
Newbie

Joined: Thu Apr 01, 2004 2:19 pm
Posts: 14
I dont have hibernate.cfg.xml file. I have hibernate.properties file, but this does not have any class names. Do I need to give one? This is how my file looks:



hibernate.connection.username=flemp_ssa
hibernate.connection.password=b0nusssa
hibernate.connection.url=jdbc:oracle:thin:@pbsxdr00047:1521:shr3d
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.dialect=net.sf.hibernate.dialect.OracleDialect


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 3:53 pm 
Newbie

Joined: Tue Dec 09, 2003 4:45 pm
Posts: 14
I'm not sure how to specify mappings in the properties file, or whether that's even possible. When you do use a properties file to do some initialization, you can let hibernate know about your mapped classes like this, provided that your mapping files are on the classpath in the same location as your class files:

Configuration cfg = new Configuration();
cfg.addClass(com.pepsi.compensation.PlanComponent.class);
.
.
.
cfg.configure();

If you've already done this, then I can't really say what's causing your problem.

_________________
Mike Davison


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 4:07 pm 
Newbie

Joined: Thu Apr 01, 2004 2:19 pm
Posts: 14
That is right, I did not add PlanComponent class to my configuration. I did that and it worked...

Thanks All


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.