Cloning JPA entity

前端 未结 8 1611
闹比i
闹比i 2020-11-29 01:55

I have a JPA entity already persisted in the database.
I would like to have a copy of it (with a different id), with some fields modified.

What is the easiest wa

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 02:43

    I just tried setting the id to null and it worked

    address.setId(null);
    address = addrRepo.save(address);
    

    setting the id to null made it so it saved into a new record with new id since i have it automatically generated.

提交回复
热议问题