This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting message "get is not valid without active transaction" while trying to delete using Hibernate

 
Monica Shiralkar
Ranch Hand
Posts: 842
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to delete User based on userId but getting message "org.hibernate.HibernateException: get is not valid without active transaction"

error message:


org.hibernate.HibernateException: get is not valid without active transaction
org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:297)
$Proxy6.get(Unknown Source)
com.dao.LoginHibernateDaoImpl.deleteUsersbyId(LoginHibernateDaoImpl.java:115)
com.web.DeleteUserAction.execute(DeleteUserAction.java:48)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


The code which leads to this message is :



thanks

 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why wait so long to start the transaction? Did you have a reason you wanted to get the User object outside the transaction?

And now you have an error message about exactly that. I suggest it shouldn't be too hard to fix the problem.
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

Monica, all methods of org.hibernate.Session should be called within active transaction.
You need to get current session then begin transaction only then use org.hibernate.Session then commit transaction then close session.
Probably all methods of org.hibernate.Session are not executed when you call them but WHEN transaction is committed (line 13 in your code).
 
Monica Shiralkar
Ranch Hand
Posts: 842
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. It worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic