Assume I have three classes, User, CreditCard and Address. User has a collection of Address objects and CreditCard has a reference to an Address object. I am not supporting shared references, so I am not making Address an entity.
Code:
public class User {
private long id;
private String name;
private Set<Address> homeAddresses=new HashSet<Address>();
private CreditCard creditCard;
//the rest of the class
public class CreditCard {
private long id;
private String owner;
private Address billingAddress;
//rest of class
public class Address {
private String street;
private String city;
Here are my mapping files:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 23, 2009 10:20:59 AM by Hibernate Tools 3.2.5.Beta -->
<hibernate-mapping>
<class name="user.CreditCard" table="PAYMENTOPTION" >
<id name="id" type="long">
<column name="ID" />
<generator class="native" />
</id>
<property name="owner" type="java.lang.String">
<column name="OWNER" />
</property>
<join table="Addresses">
<key column="ADDRESS_ID"></key>
<component name="billingAddress" class="user.Address">
<property name="city"></property>
<property name="street"></property>
</component>
</join>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 23, 2009 10:20:59 AM by Hibernate Tools 3.2.5.Beta -->
<hibernate-mapping>
<class name="user.User" table="USERS" >
<id name="id" type="long">
<column name="ID" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<set name="homeAddresses" inverse="false" lazy="true" table="ADDRESSES">
<key>
<column name="ADDRESS_ID" />
</key>
<composite-element class="user.Address">
<property name="city"></property>
<property name="street"></property>
</composite-element>
</set>
<many-to-one name="payment" class="user.PaymentOption" fetch="select">
<column name="PAYMENT_ID" />
</many-to-one>
</class>
</hibernate-mapping>
I am getting some kind of exception in the sessin factory creation. It tells me that User is un-mapped!
Any ideas? Thank you very much.
Kamal