This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Queries and Transactions" Watch "Hibernate Queries and Transactions" New topic

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.

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).

I agree. Here's the link:
subject: Hibernate Queries and Transactions
jQuery in Action, 3rd edition