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)
|