-->
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.  [ 6 posts ] 
Author Message
 Post subject: Idea for when to start transaction
PostPosted: Wed Jun 14, 2006 9:51 am 
Regular
Regular

Joined: Tue Jan 03, 2006 11:43 am
Posts: 51
Location: Sweden
Hi,

Currently, in our application, we start a transaction early in each page request regardless whether anything will be changed or not. And then close it at the end. I suspect this might be bad on the performance.

So could it be possible to start a transaction only when anything is saved to the database during a page request? (And close it at the end of the page request). Could this be done by interceptor perhaps? Or is this whole idea bad?

Btw, we use session-per-request.


/Carl


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 10:41 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
imho, opening a tran at the begin_request() is looking for bad performance down the road.

Quote:
So could it be possible to start a transaction only when anything is saved to the database during a page request? (And close it at the end of the page request). Could this be done by interceptor perhaps? Or is this whole idea bad?


imho, your DAO should have the ability to open and commit/close the tran when you call Save()/Update()/SaveOrUpdate(). check out the Cuyahoga app for a general idea on how you might do this. Also, the Castle Project has a good looking GenericDAO that other DAOs can extend:

http://www.castleproject.org/index.php/ ... GenericDao

-d


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 11:00 am 
Regular
Regular

Joined: Tue Jan 03, 2006 11:43 am
Posts: 51
Location: Sweden
In our design we don't evict the entities. We keep the session open during the entire page request. So changes are made by just changing the entities without any explicit calls to an update function in our DAO. And I'm afraid we are to long down the road on this design. Besides we want all changes made during a page request to really be inside one single transaction.

So again, might it be possible to use interceptor (or some other technique) to just begin the transaction when something has changed and its about to be persisted to the database?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 12:17 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
I had a similar question awhile ago and received the following response.

Quote:
Using tx, only for writing operation is as silly as using the safety belt only when driving and not being driven.
To be short, read operations has to be consistent as well (hence ACID), it is not faster to avoid tx, since your driver will have to do it for you under the cover.


http://forum.hibernate.org/viewtopic.php?t=944697

I'm not an expert on transactions, but, if what this Hibernate developer suggests is true, read operations should be wrapped in the transaction as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 2:58 pm 
Regular
Regular

Joined: Sun Feb 12, 2006 10:18 pm
Posts: 60
Location: Rosario, Argentina
_carl_ wrote:
In our design we don't evict the entities. We keep the session open during the entire page request. So changes are made by just changing the entities without any explicit calls to an update function in our DAO. And I'm afraid we are to long down the road on this design. Besides we want all changes made during a page request to really be inside one single transaction.

So again, might it be possible to use interceptor (or some other technique) to just begin the transaction when something has changed and its about to be persisted to the database?


What I do is use the Open Session In View pattern to open/close the session, but actually begin a transaction just before calling the SAVE method, and then commit right after it (or rollback, if required). I let NH care of all the different updates it has to do to referenced object inside the one I'm saving.
It' is also true that I don't have (for now) a very complex logic in my pages...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 10:01 am 
Regular
Regular

Joined: Tue Jan 03, 2006 11:43 am
Posts: 51
Location: Sweden
jemiller> Thanks! I guess we will continue using our approach, unless someone else has any suggestions that will not require a major redesign.
The performance isn't at all bad at the moment, but we haven't really tried it for larger amounts of data and users yet.


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