Hi all,
  I have a unique issue I could use a hand with.  Our model uses the
following inheritance

Person -> User -> Customer.


When  purchases a unit and becomes a customer, they need to
transparently be upgrade to a Customer.  In doing so, I have to copy the
UUID from the user to a customer.  We can't change the UUID b/c it is
referenced in other systems.  Our storage system is functionally
equivalent to single table inheritance.  If I simply create a new
instance and assign the same id, I receive this error.

An object of type "com.spidertracks.aviator.model.user.Customer" with
oid
"com.spidertracks.aviator.model.user.Customer-d81d5fe0-6195-11e0-861a-005056c00008"
 already exists in this context; another cannot be persisted.



The only way I've found around this is to perform the following steps.


1. load the original user, copy all the fields over that are not
relationships (I.E *toMany *toOne). 
2. Load all ids for entities that are related collections.
3. call entityManager.clear
4. Load all related collections 1 id at a time and link them to the new
customer instance.
5. Call persist with the new customer.

This is a bit of a pain, and as our entities get more complex this will
be come messier.  Is there an easier way to effectively deep copy the
statemanager from one instance to another before persisting to avoid all
these additional steps?

Thanks,
Todd


Reply via email to