-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-one: breaking due to the many-to-one mapping
PostPosted: Tue Apr 06, 2004 9:01 am 
Newbie

Joined: Tue Apr 06, 2004 8:44 am
Posts: 9
I am have a simple join in the db I am trying to make. My Transaction object has a RejectStatus object (see below). I am mapping a basic many-to-one relationship (also below) as the documentation indicates. It is just a lookup table that has a foreign-key relationship in the TRANSACTION table: TRANSACTION.REJECT_STATUS_ID is a foreign key to the REJECT_STATUS.ID column. Seems pretty simple but I seem to be missing something. I am getting a MappingException (below) indicating that the RejectStatus class is unmapped. However, I am able to insert data in a simple test case for RejectStatus and am also able to insert data for Transaction as well if I remove the many-to-one mapping...without the required foreign key value, of course. What am I missing?

Travis



Hibernate version: 2.1
database: Oracle 8i


mapping:

File: Transaction.hbm.xml
<hibernate-mapping>
<class name="com.novainfo.emt.domain.Transaction" table="transaction">
<id name="id" type="long" unsaved-value="0" column="transaction_id">
<generator class="sequence">
<param name="sequence">emt_id_sequence</param>
</generator>
</id>
...
...
<many-to-one name="rejectStatus"
class="com.novainfo.emt.domain.RejectStatus"
column="reject_status_id"
cascade="none"/>
</class>
</hibernate-mapping>

File: RejectStatus.hbm.xml
<hibernate-mapping>
<class name="com.novainfo.emt.domain.RejectStatus" table="reject_status">
<id name="id"
type="long"
unsaved-value="0"
column="reject_status_id">
<generator class="sequence">
<param name="sequence">emt_id_sequence</param>
</generator>
</id>
<property name="description">
<column name="description" sql-type="string" not-null="true"/>
</property>
</class>
</hibernate-mapping>


calling code:

com.novainfo.emt.domain.Transaction t = new com.novainfo.emt.domain.Transaction();
... setting primitive fields ...
com.novainfo.emt.domain.RejectStatus rs = new com.novainfo.emt.domain.RejectStatus();
rs.setId(12);
Configuration cfg = new Configuration().addClass(com.novainfo.emt.domain.Transaction.class);
SessionFactory sf = cfg.buildSessionFactory();
Session sess = sf.openSession();
Transaction tran = sess.beginTransaction();
sess.save(t);
tran.commit();
sess.close();


Transaction object:


public class Transaction {
private long id;
... other instance vars ...
private RejectStatus rejectStatus;

public void setRejectStatus(RejectStatus rejectStatus) {
this.rejectStatus = rejectStatus;
}
public RejectStatus getRejectStatus() {
return rejectStatus;
}
}


stack trace:

Exception in thread "main" net.sf.hibernate.MappingException:
An association from the table transaction refers to an
unmapped class: com.novainfo.emt.domain.RejectStatus
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:643)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:743)
at com.novainfo.emt.test.HibernateTest.makeTrans(HibernateTest.java:95)
at com.novainfo.emt.test.HibernateTest.main(HibernateTest.java:20)


Top
 Profile  
 
 Post subject: I can answer my own question
PostPosted: Tue Apr 06, 2004 9:28 am 
Newbie

Joined: Tue Apr 06, 2004 8:44 am
Posts: 9
I was not adding the child class to the Configuration...just the parent. I add the child to the Configuration and it fixes the problem.


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