views:

43

answers:

2

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new?

I am thinking I might create a session interceptor to force every entity to look new and ensure the id is left blank like a new unpresisted entity would.

+1  A: 

You can implement the Clone method in your class. It is up to you to decide how to do this (swallow or deep copy). The identity property must be set to the 'unsaved-value' declared in the mapping file, so that NHibernate knows it is a new object.

kgiannakakis
A: 

I found this topic on the NHForge forum. Check out session.merge.

BennyM