-->
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.  [ 3 posts ] 
Author Message
 Post subject: Rolling back the WHOLE transaction?
PostPosted: Tue Sep 30, 2003 10:47 pm 
Newbie

Joined: Tue Sep 30, 2003 10:39 pm
Posts: 1
Location: Missouri
I'm experiencing a very weird problem using Hibernate 2.0 in a Session bean environment (JBoss and
eventually WebLogic). I'm using a DataSource enlisted with JTA.
I have some nested objects (say, Person with a list of Address
objects attached). If I populate all required fields (e.g.
not-null in the database), everything works fine. However,
if I omit a required field from a nested object (e.g. line1 from
an Address object) and then save the Person object, I get a NULL
field violation, just like I expect to. However, the Person object
still gets saved. This sort of makes sense, because as far as the
database is concerned, there's nothing wrong with the Person record. However, from an app server perspective, this seems like aberrant behaviour, and I would definitely like to avoid it!
I would like to roll back the whole transaction if anything
fails. If I make my session bean use BMT, I can do that, but only then. Is there any other way to get the behaviour I need?

Here's an example of some code in my session bean:


Code:
public Person save(Person p)
   throws MyAppException
{
   Session session = null;
   try
   {
      session = getSessionFactory().openSession();
      if(p.getId() == null)
         session.save(p);
      else
         session.update(p);
      session.flush();
   }
   catch(Exception e)
   {
      throw new MyAppException(e);
   }
   finally
   {
      try
      {
         session.close();
      }
      catch(Exception e)
      {}
   }
   return p;
}

_________________
"In theory, there is no difference between theory and practice. In practice, there is." -- Yogi Berra


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 3:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You need to tell the JTA transaction that you you require the transaction to be rolled back, eg, tx.setRollbackOnly().


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 4:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Or let a RuntimeException been thrown through EJB call which do the setRollBackOnly for you.


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

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.