aspose file tools*
The moose likes Object Relational Mapping and the fly likes getting message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "getting message "get is not valid without active transaction" while trying to delete using Hibernate" Watch "getting message "get is not valid without active transaction" while trying to delete using Hibernate" New topic
Author

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

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 644
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
Bartender

Joined: Oct 14, 2005
Posts: 18659
    
    8

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 Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

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).


True person is moral, false is right!
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 644
Thanks. It worked.
 
Don't get me started about those stupid light bulbs.
 
subject: getting message "get is not valid without active transaction" while trying to delete using Hibernate