-->
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: Query without transaction ?
PostPosted: Wed Apr 21, 2004 11:38 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 6:16 am
Posts: 40
Location: Luxembourg
Is it possible to query the database without opening a transaction , i.e is it enough if I have an open Session ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 11:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
there is ALWAYS a transaction and it is a best practice to ALWAYS explicitly manage the transactions even for read only queries


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 5:43 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
I use Hibernate sessions for SELECTs and use Transactions for INSERTs, UPDATEs and DELETEs. I have not come across any documentation that suggests a necessity for Transactions in SELECT situations. But I could be wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 5:55 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you'll find many posts discussing about this.
I've made the error of not using transaction for select because i thought it was unecessary, i was wrong...
You must know that even a select create in fact

begin transaction
select...
commit


because in most of the cases, db is configured with autocommit


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 6:03 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
But if you don't have anything to commit/rollback, why even have a transaction. The 4 methods in Transaction are commit(), rollback(), wasCommitted() and wasRolledBack(). If you don't need to do any of these, why create a transaction. If you call transaction.commit() for a SELECT statement, don't you end up opening yourself up to the possibility of updating data by some fluke chance. While the example in the javadocs for Session talks of using transaction, it seems to pertain more to modification of persistent objects, not retrieval of data.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 7:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There always is a transaction when doing database access, JDBC just uses autocommit by default, meaning it will commit and start a new transaction for every statement. Guys, this has been discussed a hundred times already, please search the forum.


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.