permaculture playing cards
The moose likes Object Relational Mapping and the fly likes Hibernate Queries and Transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Queries and Transactions" Watch "Hibernate Queries and Transactions" New topic
Author

Hibernate Queries and Transactions

Bai Shen
Ranch Hand

Joined: Sep 24, 2008
Posts: 323
I've set up some Hibernate transactions and queries to select data from the database, update it, and then save the results back to the database.

However, now I just want to get a list of some of the items in the database. I don't need to make any changes at all. So I don't need to commit or rollback. However, will just running the query leave the transaction open if I don't call commit or rollback?

What's the proper way to query the database if you don't intend to change anything? I couldn't seem to find anything concerning this in the searches I did.

TIA.
Angel Taveras
Ranch Hand

Joined: Nov 13, 2008
Posts: 84

Hello Bai, i don't know if it leaves the transaction open or not, i think that it depends.

It depends on the transaction manager that you are using if any, and if the there it's a
transaction timeout associated with it.

I prefer to always starts and commit a transaction to denote a unit of work. It's a nice
recommendation, 'cause, some of the objects associated with the session can be eligible for GC (if no caching is used).

regards,
 
Don't get me started about those stupid light bulbs.
 
subject: Hibernate Queries and Transactions