I SOLVED THIS.
I created a component that makes this whole process for you based on the annotations of the package (javax.persistence
).
Component already sets the id of the entity to null. He does all the analysis of the algorithm to be applied based on the type of each attribute relationship @OneToMany
, @OneToOne
or @ManyToMany
.
Example
Person person = personDAO.find(1);
PersistenceCloner cloner = new PersistenceCloner(person);
Person personCopy = cloner.generateCopyToPersist();
Download JAR and SOURCES: jpa-entitycloner
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…