Hi Friends,
I am using hibernate 3.2.5.
I have a parent table P. It has 2 children C1 & C2, my requirement is if there is a Exception while saving C1 or C2 the parent also should not be saved ie., the transation should rollback.
But its not happening with the following code, the parent is getting saved & ofcourse the child which has Exception is not saving.
<class name="com.uprr.app.apx.model.APXInvoice"
table="APX_FEDR_INVC">
<composite-id name="invoicePK" class="com.uprr.app.apx.model.InvoicePK">
<key-property name="entitySeqNumber" column="ENTY_SEQ_NBR" />
<key-property name="entityCode" column="ENTY_CD" />
<key-property name="invoiceNumber" column="INVC_NBR" />
</composite-id>
Other propeties
<property/>
.
.
.
<property/>
<set name="invoiceDistributions" lazy="true"
cascade="all">
<key>
<column name="ENTY_SEQ_NBR" />
<column name="ENTY_CD" />
<column name="INVC_NBR" />
</key>
<one-to-many
class="com.uprr.app.apx.model.InvoiceDistribution" />
</set>
<set name="invoiceErrors" lazy="true"
cascade="all">
<key>
<column name="ENTY_SEQ_NBR" />
<column name="ENTY_CD" />
<column name="INVC_NBR" />
</key>
<one-to-many
class="com.uprr.app.apx.model.InvoiceError" />
</set>
</class>
This is the code in the saveMethod
public void saveInvoice(APXInvoice invoice) throws DAOException {
Session session = getSession();
Transaction tx = session.beginTransaction();
try {
getHibernateTemplate().save(invoice);
tx.commit();
System.out.println("Success");
} catch (Exception e) {
System.out.println("Failure");
tx.rollback();
throw new DAOException(e);
}
}
Thanks in advance
_________________ New Problems, New Ideas.
|