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: JDBCTransaction committing on rollback ?
PostPosted: Thu Mar 10, 2005 12:15 pm 
Newbie

Joined: Mon Jun 07, 2004 9:18 am
Posts: 13
Location: Torino, Italy
Hi,

I have a doubt about how Hibernate's JDBCTransaction works, and how handles "nested" transactions.

Here's the code:

Code:
Transaction tx1 = session.beginTransaction();

// Start Block 1
User user = new User();
user.setName("blah"); // Name has unique constraint

Account account = new Account();
account.setUser(user);

Transaction tx2 = session.beginTransation();
session.save(user);
session.save(account);
tx2.commit();
// End Block 1

user.setLogin("duplicate"); // Violates unique constraint
session.update(user);
tx1.commit();


What happens is that tx1 never commits since violates the unique constraint on user.name, but nonetheless I get the user and the account inserted in the DB.

Note that the code in "Block 1" can be a call to another method that may not have knowledge that an "external" transaction has been started, and that the method can be used independently from the code shown.

I did not try, but I guess the same code in JTA environment works fine, that is no records are inserted in the DB (I'm going to try this).
I noticed that JTATransaction knows if it started the transaction or not, and behaves differently on commit/rollback, while I could not see this behavior in JDBCTransaction.

The question is: is this expected JDBCTransaction behavior ?
If so, how can I modify the code above considering that "Block 1" can be a method on its own ?
Is my last resort using a TransactionManager and JTATransaction ?

Thanks,

Simon

Hibernate version:
2.1.8


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.