It's possible although it would be more consistent to clone this object since this is what you want to achieve in the principle.
You need two things :
1) check the entity is not managed by an open session. If so, do a session.evict(thisEntityInstance) to remove this management.
2) As suggested above, put the value in the id that Hibernate will understand as identifying a new instance. If the key is an object, it's often a null value. If the key is a native type, then it's often 0. See unsaved-value attribute on the <id> tag if it's been specified.
After that, any session.save() on the instance should trigger an insert at the session flush().
_________________ Baptiste
PS : please don't forget to give credits below if you found this answer useful :)
|