• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session closed

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does close the session. How can prevent session from closing when Tx is comitted.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it doesn't.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Here is my code, I get this exception

Exception in thread "main" org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1621)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.createQuery(Unknown Source)
at com.pradeep.TestHibernate.main(TestHibernate.java:29)
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm curious, why are you using getCurrentSession() and explicitly commiting a transaction? This may have something to do with the behaviour you are seeing.

The documentation states all commit() should do with the session is flush it. What you may be seeing could be a bug, but then the code you've written is not really how Hibernate is expected to be used.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is from Hibernate in Persistence book. So session.flush() commits a Tx ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep bhatt wrote:This is from Hibernate in Persistence book. So session.flush() commits a Tx ?


No, transaction.commit() does.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic