Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi,
I am just trying to do a simple insert with a many-to-one association. I am getting an association references an unmapped class exception.
Hibernate version: 3.0.5
Mapping documents:
hibernate-cfg.xml
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@skanchirajulptp:1521:TEST</property>
<property name="connection.username">scott</property>
<property name="connection.password">scott</property>
<property name="connection.schema">scott</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create-drop</property>
<mapping resource="Imdscannedconfig.hbm.xml"/>
<mapping resource="Net.hbm.xml"/>
net.hbm.xml
<class name="com.hibernate.example.pos.Net" table="NETS">
<id name="id" >
<column name="NET_ID" not-null="true"/>
<generator class="sequence"/>
</id>
<property name="name">
<column name="NET_NAME"/>
</property>
<set name="imdscannedconfig"
inverse="true"
cascade="save-update">
<key column="NET_ID"></key>
<one-to-many class="Imdscannedconfig"/>
</set>
</class>
imdscannedconfig.hbm.xml
<class name="com.hibernate.example.pos.Imdscannedconfig" table="IMDSCANNED">
<id name="id">
<column name="IMDS_ID" not-null="true"/>
<generator class="sequence"/>
</id>
<property name="configName">
<column name="IMDS_NAME" length="16" not-null="true"/>
</property>
<many-to-one name="net"
column="NET_ID"
class="Net"
not-null="true"/>
</class>
Code between sessionFactory.openSession() and session.close():
Net testnet = new Net();
testnet.setName("Net 1");
Imdscannedconfig candConfg = new Imdscannedconfig();
candConfg.setConfigName("Test Canned Configuration");
testnet.addImdscannedconfig(candConfg);
sess.save(testNet);
code for addImdscannedconfig()
public void addImdscannedconfig(Imdscannedconfig imdscand)
{
imdscand.setNet(this);
this.getImdscannedconfig().add(imdscand);
}
Full stack trace of any exception that occurs:
java.lang.ExceptionInInitializerError
at com.hibernate.example.util.HibernateUtil.<clinit>(HibernateUtil.java:29)
at com.hibernate.example.test.NetCanned.main(NetCanned.java:41)
Caused by: org.hibernate.MappingException: Association references unmapped class: Imdscannedconfig
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2036)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2497)
at org.hibernate.cfg.HbmBinder$SecondPass.doSecondPass(HbmBinder.java:2468)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:884)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)
at com.hibernate.example.util.HibernateUtil.<clinit>(HibernateUtil.java:27)
... 1 more
Exception in thread "main"
Name and version of the database you are using:
Oracle 10g
Thanks in advance for the help.
-Surya