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

前端 未结 9 655
抹茶落季
抹茶落季 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

    You could use mapstruct and create a method copy from object to object while ignoring id and every field that you don't want to copy.

    If you have asscociations like one to many, many to many etc. you must have also a copy method in their mappers.

    For binding children with parents, you can use afterMapping annotation and have add methods like Vlad Mihalcea has posted and do your work there or just do it in a service

提交回复
热议问题