Aaron Fischer
Aaron Fischer

Reputation: 21211

How Do I copy an existing nhibernate object as a new object?

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.

Upvotes: 0

Views: 1059

Answers (2)

kgiannakakis
kgiannakakis

Reputation: 104178

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.

Upvotes: 1

BennyM
BennyM

Reputation: 2856

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

Upvotes: 0

Related Questions