-->
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.  [ 5 posts ] 
Author Message
 Post subject: Necessary to use transactions for read-only queries
PostPosted: Fri Aug 05, 2005 3:14 pm 
Newbie

Joined: Thu Aug 04, 2005 5:52 pm
Posts: 3
I am using hibernate from within a managed weblogic server.
All my queries are read-only
Is it necessary to use
s = openSession();
t = s.beginTransaction();

<logic>

t.commit();
s.close();


or

s = openSession();
<logic>
s.close();

should suffice.
Does hibernate set autoCommit to false ?


Top
 Profile  
 
 Post subject: Re: Necessary to use transactions for read-only queries
PostPosted: Fri Aug 05, 2005 3:32 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 10:27 am
Posts: 23
anjana wrote:
I am using hibernate from within a managed weblogic server.
All my queries are read-only
Is it necessary to use
s = openSession();
t = s.beginTransaction();

<logic>

t.commit();
s.close();


or

s = openSession();
<logic>
s.close();

should suffice.
Does hibernate set autoCommit to false ?


If you're doing Read-Only, you won't need to start a transaction. Transactions are good for making sure all logic within that transaction is completed as a whole. Think of a Transaction as single unit of work.

_________________
- Richard Burton


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 06, 2005 3:18 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Transactions are necessary to access database, "read-only" transaction is a transaction too, but it is not necessary to manage transactions if container manages this stuff.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 06, 2005 8:24 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 8:51 pm
Posts: 20
Location: Bergamo, Italy
so it is possible to NOT use t = s.beginTransaction(); when i make a read only?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 07, 2005 7:24 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
See documentation about configuration and managed transactions, hibernate integrates with container and you can use declarative transaction demarcation. I prefer to use client transactions, it is more clear for me. Typical transaction demarcations is a transaction per request anyway. It is a web application, is not it ? If it is a web application then demarcate transactions in filter or in "controler" implementation, you can change filter to use local (hibernate transaction API) or remote transactions ("UserTransaction" from JTA API). Do not use transaction demarcation in transaction processing code (transaction is per usecase and the same method can be used in many places), but same rules are valid for all transactions. Databases have "readonly" transaction concept ("SET TRANSACTION READONLY"), you can set this transaction attribute in filter too, but you always need to demarcate transactions in some way to avoid random data (it can happen for "readonly" operations with wrong transaction demarcation too )


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