Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsHelp on clone method
https://www.eclipse.org/forums/index.php/mv/msg/352549/873076/#msg_873076
@Override
public SomeEntity clone() throws CloneNotSupportedException {
SomeEntity clone = (SomeEntity) super.clone();
clone.setId(null);
clone.setCreatedDateTime(null);
clone.setCreatedUser(null);
return clone;
}
Finally, how could I go about testing this scenario?
]]>Tim MacEachern2012-05-17T13:15:02-00:00Re: Help on clone method
https://www.eclipse.org/forums/index.php/mv/msg/352549/873245/#msg_873245
EclipseLink will use its own methods to create backups and working/managed instances, which involves creating a new instance and populating it with the required attributes. This is configurable though through a copy policy described here: http://wiki.eclipse.org/EclipseLink/Features/Core#Clone.2FCopy_Policy
and http://wiki.eclipse.org/Configuring_a_Descriptor_%28ELUG%29#Configuring_Copy_Policy
with the default being the InstantiationCopyPolicy. If JPA method access and weaving is used, the default is a PersistenceEntityCopyPolicy which uses a _persistence_shallow_clone() method.
I've found duplicates can occur when objects are not correctly persisted/merged, but that probably doesn't help track down how to find them. Adding debugging to your entities themselves and turning EcliseLink logging to finest so you can see where they might get inserted could help. I believe EclipseLink will print off the entity as persist/merge gets called on it at the finest log level.
Best Regards,
Chris]]>Chris Delahunt2012-05-17T19:48:56-00:00