I am not sure what you mean by "lazy load the bean." If you mean "lazy load" some of the attributes inside the bean, then you need to decided if those lazy loaded elements are to be part of your deep copy.
If they are to become part of the deep copy, there is no need to lazy load anything because you are going to require the data anyways.
You will need to make sure that each of the objects, including all of the complex attributes have a clone() method and implement the interface Cloneable. I would also null out the association between the parent and child attributes. For instance, if you have the following two classes:
Code:
public class Parent implements Cloneable {
private String key;
private String name;
private Child child;
// getters and setters
public void setChild(Child child) {
this.child = child;
this.child.setParent(this);
}
public Object clone() {
Parent ret = new Parent(this);
ret.setChild((Child)child.clone());
return ret;
}
}
public class Child implements Cloneable {
private String key;
private String name;
private Parent parent;
// getters and setters
public Object clone() {
Child child = new Child(this);
child.setParent(null);
return child;
}
}
You need to make sure that the child clone sets its parent as the new cloned parent instance.
If this helps, don't forget to rate! :)