• Post Reply Bookmark Topic Watch Topic
  • New Topic

CurrentSession vs openSession

 
indu iyengar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

am a new bee to Hibernate.. When starting itself I got strucked at session Issue..
when I open session in this way , while closing the session and if I use in this way , seesion closed quitely..
what's the difference between current session and opensession
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Current session is the session associated with the current JTA transaction. If you have configured Hibernate to use a Session per transaction this is the method to use. The session will close when the transaction commits.
 
indu iyengar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply..

but I have one doubt .. which one is better ?
In what cases we use these two ? generally which is the preferable one ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which suits your needs better? JTA might be a big overhead for your application, but grouping session usage into one business transaction might may be more efficient (since it will use the first level cache better).
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!