Hi,
I have to classes VendorDateEntry and UserDateEntry that both extend
a class DateEntry. I have a class EntryContainer that has a mixed list of VendorDateEntries and UserDateEntries. I want to use a table-per-concrete class strategy for VendorDateEntry and UserDateEntry.
After a lot of trial an error I finally found a mapping that works, i.e. the database tables look the way I expect them to look and the retreived objects are correct. The problem I have now, is that cascade="all-delete-orphan" does not work, i.e. when I delete a DateEntry from the list in EntryContainer, the corresponding table row is still there, although it is not contained in any list.
All suggestions are welcome.
All help is appreciated.
Here are my data:
hibernate version: 2.1.4
DB version: MySQL 4.1.1a
<hibernate-mapping>
<class
name="de.oew.test.EntryContainer"
table="test_entry_container"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<list
name="dateEntryList"
table="test_entry_list"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
outer-join="auto"
>
<key
column="container_id"
/>
<index
column="entry_position"
/>
<many-to-any
meta-type="class"
id-type="long">
<!-- VendorDateEntry, UserDateEntry -->
<column name="entry_type"/>
<column name="entry_id"/>
</many-to-any>
</list>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="de.oew.test.UserDateEntry"
table="test_user_date_entry"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<property
name="date"
type="date"
update="true"
insert="true"
column="date"
/>
<property
name="text"
type="java.lang.String"
update="true"
insert="true"
column="text"
/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="de.oew.test.VendorDateEntry"
table="test_vendor_date_entry"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<property
name="date"
type="date"
update="true"
insert="true"
column="date"
/>
<property
name="text"
type="java.lang.String"
update="true"
insert="true"
column="text"
/>
</class>
</hibernate-mapping>
Java code:
private static void saveOrUpdate(Object object) throws HibernateException{
try{
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
session.saveOrUpdate(object);
tx.commit();
}
catch(HibernateException exc){
exc.printStackTrace();
}
finally{
HibernateUtil.closeSession();
}
}
|