I use datanucleus 6 for the persistence of my java classes. A class extends a super class and overwrites the clone method. Both classes are persistable. The enhancer therefore creates a dnClone method and a clone method calling the dnClone method.
Object clone() {
XXX copy = (XXX)dnClone();
copy.dnFlags = (byte) 0;
copy.dnStateManager = null;
return copy;
}
The superclass' enhanced clone and dnClone methods looks like this:
public Object clone() throws CloneNotSupportedException {
MySuperClass copy = (MySuperClass)this.dnClone();
copy.dnFlags = 0;
copy.dnStateManager = null;
return copy;
}
public Object dnClone() throws CloneNotSupportedException {
MySuperClass dc = new MySuperClass(this.id);
....
return dc;
}
The not enhanced clone method of the extending class looks like that:
public Object clone() throws CloneNotSupportedException {
Object oCloned = super.clone();
ExtClass edc = new ExtClass((MySuperClass)oCloned);
edc.setFinishedBy(finishedBy);
return edc;
}
The enhanced clone and dnClone method of the extending class look like this:
public Object clone() throws CloneNotSupportedException {
ExtClass copy = (ExtClass)this.dnClone();
copy.dnFlags = 0;
copy.dnStateManager = null;
return copy;
}
public Object dnClone() throws CloneNotSupportedException {
Object oCloned = super.clone();
ExtClass edc = new ExtClass((MySuperClass)oCloned);
edc.setFinishedBy(this.finishedBy);
return edc;
}
Calling the super.clone() method within the ExtClass' clone method therefore leads to the own dnClone method being called by the call of the this.dnClone method within the superclass' clone method.
This causes an infinite loop.
Is there an option that can be set for the enhancer for only creating a single clone method like it was created through datanucleus 5 enhancer?