I sifted through the documentation and this forum, but am having trouble finding what I am doing wrong. I am persisting a class "Person" which contains a set of "Address" objects. The person persists fine, but none of the addresses in the set persist. Here is what I am doing ...
person.hbml.xml
<hibernate-mapping>
<class name="com.uvalodge.person.Person" table="person">
<id name="uid">
<generator class="identity"/>
</id>
<property name="firstName"/>
<property name="lastName"/>
<set name="addresses" lazy="true">
<key column="person_uid"/>
<one-to-many class="com.uvalodge.person.Address"/>
</set>
</class>
</hibernate-mapping>
address.hbm.xml
<hibernate-mapping>
<class name="com.uvalodge.person.Address" table="address">
<id name="uid">
<generator class="identity"/>
</id>
<property name="address1"/>
<property name="address2"/>
<property name="city"/>
<property name="state"/>
<property name="zip"/>
</class>
</hibernate-mapping>
Then in my calling code I do the following....
Configuration cfg = new Configuration();
cfg.addClass(Person.class).addClass(Address.class);
Person p = new Person();
p.setFirstName("First");
p.setLastName("Last");
Address a = new Address();
a.setAddress1("Here");
a.setAddress2("Apt 101");
a.setCity("Arlington");
a.setState("VA");
a.setZip("22203");
Set s = new HashSet();
s.add(a);
p.setAddresses(s);
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session sess = sessionFactory.openSession();
Transaction transaction = sess.beginTransaction();
sess.save(p);
transaction.commit();
sess.close();
I tried setting the attribute cascade="all" on the set element, but it does not seem to affect anything. Anyone have any thoughts?
|