Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Queries and Transactions

 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic