This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 594
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: 18541
    
    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: 594
Thanks. It worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting message "get is not valid without active transaction" while trying to delete using Hibernate
 
Similar Threads
Hibernate Envers : How to delete entries from my audit table?
Problem with inserting new data into database using hibernate
Reading All the records from a table + Hibernate
Transaction and non-transaction in Hibernate DAO
Getting Hibernate Exception:Clear is not valid