Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does Hibernate3 query require a transaction?

 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is my following get method sufficient for querying with Hibernate3 or do I need to wrap it in a transaction and commit and close the session? I have seen it done both ways but I am looking for the proper way to do this. Thanks.

 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't anyone help with this one? Everyone who uses hibernate must use a query. Any suggestions???
 
Michael Duffy
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andy Hahn:
Is my following get method sufficient for querying with Hibernate3 or do I need to wrap it in a transaction and commit and close the session? I have seen it done both ways but I am looking for the proper way to do this. Thanks.

 
Michael Duffy
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andy Hahn:
Is my following get method sufficient for querying with Hibernate3 or do I need to wrap it in a transaction and commit and close the session? I have seen it done both ways but I am looking for the proper way to do this. Thanks.




Sorry, bad mouse click.

Queries being read only, I'd say you don't need a transaction. There's nothing to commit, after all.

If you're doing lazy loading, you might need to keep a session open, but that's not the same as a transaction.

EJB session beans that are used to correct the (n+1) query problem require transactions, but I don't believe they're necessary here.
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic