-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Rollback Problem
PostPosted: Thu Jul 17, 2008 6:32 am 
Newbie

Joined: Thu Jul 17, 2008 6:15 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.