This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes PersistentObjectException: detached entity passed to persist  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "PersistentObjectException: detached entity passed to persist  " Watch "PersistentObjectException: detached entity passed to persist  " New topic
Author

PersistentObjectException: detached entity passed to persist

jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
I'm trying to do a simple persisting of an object into a MySQL database , with the following code:

When I run this I'm getting a org.hibernate.PersistentObjectException: detached entity passed to persist .The full stacktrace is as follows:

srinivas bodduluri
Greenhorn

Joined: Feb 26, 2009
Posts: 3
The way you presented in the first code snippet for the lines is wrong.

you need to create UserBean object after beginning the transaction.

or what you can do is

instead of em.parsist just use merge. since user object in the above code treat it as detached object. you will have to reattach by using merge but not with parsist.


 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: PersistentObjectException: detached entity passed to persist
 
It's not a secret anymore!