[英]How to Delete Entity from Database and Store a Clone in a Different Database Table in Java/Spring/Hibernate
My goal is我的目标是
Thanks谢谢
My suggestion is to not delete first, but rather copy the entity into the table you wish, make sure it is successfull by checking the result code, then delete the entity from the table.我的建议是不要先删除,而是将实体复制到您想要的表中,通过检查结果代码确保它成功,然后从表中删除实体。
INSERT INTO copy_table
SELECT * FROM original_table
WHERE condition;
DELETE FROM original_table
WHERE condition;
In JPA在 JPA
https://docs.spring.io/spring-data/jpa/docs/1.5.0.RELEASE/reference/html/jpa.repositories.html https://docs.spring.io/spring-data/jpa/docs/1.5.0.RELEASE/reference/html/jpa.repositories.html
Entity x = jpaRepository.findById(id);
cloneTableJpaRepo.save(x);
jpaRepository.delete(x);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.