-->
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.  [ 4 posts ] 
Author Message
 Post subject: Is it necessary to wrap a simple find() in a transaction?
PostPosted: Wed Jun 09, 2004 3:18 pm 
Newbie

Joined: Wed Jun 09, 2004 3:13 pm
Posts: 2
Location: scottsdale, az.
Is this considered a 'best practice' for some reason? Why would this be? Example:

Transaction tx = session.beginTransaction();
List blahList = session.find("from Blah");
tx.commit();

Not sure why I would 'need' to do this, but lots of examples in the manual do it this way. If I do have to do this for some reason, do I also need to rollback() if I catch an exception?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 5:56 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
One rule: always use transaction, yes it is a best practice.

i think most of us have made the same mistake but always use transaction even for read-only access

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 6:40 pm 
Newbie

Joined: Wed Jun 09, 2004 3:13 pm
Posts: 2
Location: scottsdale, az.
Ok, Thanks for the reply, I will just 'believe you(!) and keep doing it. :)

But is there any place you or anyone can point me with an explanation as to exactly why this is a good practice? Something that perhaps would give me a clue as to what is going on that would make this necessary or desirable? Is it possible that this has to do with cache consistency or something like that? If I ask for an object but there is some kind of error populating it and it is only partially retrieved, does it put the cache in some sort of invalid state if I don't use the transaction? Just a guess...perhaps I am way ahead of myself here.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 8:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It has been discussed numerous times on that forum, just search for it. Basically there is no such thing as "no transaction". You will always have a transaction, the question is just where it is demarcated.


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