-->
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.  [ 8 posts ] 
Author Message
 Post subject: Are transactions needed for collection iteration read-only?
PostPosted: Wed Dec 03, 2003 7:02 pm 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
My application uses a JDBC connection and it only has one thread (main) at the moment. The service methods commit the changes whenever required. There are some places where iterating the collection is necessary. Based on the result, I may have to change the data (and hence a commit).
Given this, should I start a transaction before the collection is read? I am sure that this process is not going to change the data. I just want to save some runtime openSession and closeSession if they are not really required.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 7:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You should always use a Transaction even for read only data.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 7:41 pm 
Beginner
Beginner

Joined: Mon Nov 10, 2003 7:09 pm
Posts: 28
Allow me to ask a stupid question - Why is it necessary to have a transaction for a read only operation? If the data will never be updated, what purpose does the transaction serve?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 8:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Not a silly question as lots of people assume you don't need one as well.
Its all a question of data consistency. Many database vendors will add a read lock when doing selects, also database data caching etc are tied to the transaction model. The transaction manages these aspects. I think people get the idea of no transactions necessary due to the use of auto-commit being on by default for standard JDBC connections. The black magic just happens - the transaction is there in reality. In hibernate the transaction auto-commit is off so you must do it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 9:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
auto-commit doesn't really mean "no transactions". it means "a new transaction for every statement", and is usually slower than no autocommit


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 5:35 pm 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
Again, this might be a silly question! Suppose, I begin a transaction for a read-only operation and I couldn't find what I wanted from the collection, should I do a rollback or commit? At this point, is there a difference in the low-levels between rollback and commit?

I am asking this because I always do a commit before close for any operation that did not produce any exception and I want to make sure that I am okay for the scenario I explained above.

Thanks!
Madhan.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 5:37 pm 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
One more addition to my question... Should I necessarily do either a rollback or commit?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 8:20 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
commit is ok


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