In Java, there is no easy way to deeply clone objects; therefore, Hibernate has no specific support for this.
This suggests that you can access the Hibernate annotations from your deep copy code and use them to determine what to do - you can even add your own annotations (to stop the deep copy code by cloning static master data).
Thus, it should be possible to write an implementation that works this way, and uses the @Id annotation and some of your encoding rules to make this happen.
Using stored procedures may also work, depending on the database you are using and how much you match SQL. But the resulting code will be difficult for the core, testing and understanding. Therefore, I propose against this.
Aaron digulla
source share