-->
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.  [ 2 posts ] 
Author Message
 Post subject: transaction boundaries are violated?
PostPosted: Tue Jun 06, 2006 7:17 pm 
Newbie

Joined: Tue Nov 11, 2003 4:22 am
Posts: 2
If I use two separate transactions in one session to read objects and between those I update the object read in first transaction - then the object is written to the database when second transaction is commited, even though I read completely different objects.
As far as I understand the code below (between sessionFactory.openSession() and session.close()) is translated into something like this:
1. start
2. read A
3. commit
4. update A
5. start
6. read B
7. commit

Why commit at line 7 commits update 4, which happened before start at line 5? What can I do to avoid this?

Yes, I know that documentations says that there should be one transaction per session. Current situation occured when I tried to use spring declarative transactions - I read two objects from different xxxService, where service methods where surrounded by Springs' declarative transactions. I dont think that I should split those different service methods into one to have one transaction.
And, you can ask - why should one update the object outside transaction? That happened because I pass object A to the web tier to display it and I need to temporarily replace real url with Fake (it will not be updated by web tier)

Hibernate version:
3.0
Mapping documents:
not important
Code between sessionFactory.openSession() and session.close():
//first transaction
Transaction tx = s.beginTransaction();
Site site = (Site)s.get(Site.class, 1);
tx.commit();
// update outside transactions
site.setUrl("FakeURL");
// another transaction
tx = s.beginTransaction();
ContentPackage cp = (ContentPackage)s.get(ContentPackage.class, 1);
tx.commit();

Name and version of the database you are using:
PostgreSQL 8.1

_________________
Regards, Andrey Grishin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 7:29 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Most transaction managers, include JDBC transactions, do not support "nested" transactions. There is only one transaction per JDBC connection, and if you commit it, everything is committed.

If you're using a more advanced transaction manager, for example JTA or whatever J2EE provides, you may be able to arrange for named transactions, so that committing transaction X doesn't affect transaction Y at all. I don't know if this is possible, I stick with JDBC.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.