Hi,
I'm using Middlegen to generate the mappings for hibernate, and then generate the classes with java net.sf.hibernate.tool.hbm2java.CodeGenerator, so no typo from my part.
As this is my first contact with Hibernate, I'm trying something not too difficult on a test db: I'm working on the table customer_status (with class CustomerStatu), which is only referenced from tables customers (class Customer).
I have a problem with this part of the mapping of customer_status (complete mapping below):
Code:
<set
name="customers"
lazy="true"
inverse="true"
>
<key>
<column name="customer_status_id" />
</key>
<one-to-many
class="custdb.hibernate.Customer"
/>
</set>
By that I mean that if I remove it from the mapping file, it works perfectly.
I can retrieve a customer status and work on it:
CustomerStatu customer = (CustomerStatu) session.load(CustomerStatu.class, custId);
System.out.println("name of customerstatus =" +customer.getCustomerStatusName());
When I leave the set in the mapping I get:
Exception in thread "main" net.sf.hibernate.MappingException: Association references unmapped class: custdb.hibernate.Customer
This seems a frequent question but didn't find the fix corresponding to my situation (searched the forum, the FAQ, the reference docs, ...).
Thanks in advance for your help.
Raph
Customer Status mapping Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="custdb.hibernate.CustomerStatu"
table="customer_status"
>
<id
name="customerStatusId"
type="int"
column="customer_status_id"
>
<generator class="assigned" />
</id>
<property
name="customerStatusName"
type="java.lang.String"
column="customer_status_name"
not-null="true"
length="-1"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to Customer -->
<set
name="customers"
lazy="true"
inverse="true"
>
<key>
<column name="customer_status_id" />
</key>
<one-to-many
class="custdb.hibernate.Customer"
/>
</set>
</class>
</hibernate-mapping>
Customer mappingNot sure it is needed, but here is is
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="custdb.hibernate.Customer"
table="customers"
>
<id
name="customerId"
type="int"
column="customer_id"
>
<generator class="assigned" />
</id>
<property
name="name"
type="java.lang.String"
column="name"
length="-1"
/>
<property
name="description"
type="java.lang.String"
column="description"
length="-1"
/>
<property
name="vat"
type="java.lang.String"
column="vat"
length="-1"
/>
<!-- associations -->
<!-- bi-directional many-to-one association to CustomerStatu -->
<many-to-one
name="customerStatu"
class="custdb.hibernate.CustomerStatu"
not-null="true"
>
<column name="customer_status_id" />
</many-to-one>
<set
name="customers2accountManagers"
lazy="true"
inverse="true"
>
<key>
<column name="customer_id" />
</key>
<one-to-many
class="custdb.hibernate.Customers2accountManager"
/>
</set>
<!-- bi-directional one-to-many association to CustomerOrder -->
<set
name="customerOrders"
lazy="true"
inverse="true"
>
<key>
<column name="customer_id" />
</key>
<one-to-many
class="custdb.hibernate.CustomerOrder"
/>
</set>
<!-- bi-directional one-to-many association to Customers2contact -->
<set
name="customers2contacts"
lazy="true"
inverse="true"
>
<key>
<column name="customer_id" />
</key>
<one-to-many
class="custdb.hibernate.Customers2contact"
/>
</set>
<!-- bi-directional one-to-many association to Customers2address -->
<set
name="customers2addresss"
lazy="true"
inverse="true"
>
<key>
<column name="customer_id" />
</key>
<one-to-many
class="custdb.hibernate.Customers2address"
/>
</set>
</class>
</hibernate-mapping>