How to deep copy a Hibernate entity while using a newly generated entity identifier

前端 未结 9 661
抹茶落季
抹茶落季 2020-12-30 20:05

I\'m using a relational DB using a single column pk with a few nested tables.

I need to add a simple archiving to my project. The archiving only happens when the appl

9条回答
  •  旧巷少年郎
    2020-12-30 20:53

    1- Add commons-lang dependency to pom.xml file

    
        commons-lang
        commons-lang
        2.6
    
    

    2- Import org.apache.commons.lang.SerializationUtils

    3- Use SerializationUtils.clone(oldObj)

    ex. Class1 newObj = (Class1) SerializationUtils.clone(oldObj);

    see also java-deep-copy

提交回复
热议问题