简体   繁体   English

如何在 Java/Spring/Hibernate 中从数据库中删除实体并将克隆存储在不同的数据库表中

[英]How to Delete Entity from Database and Store a Clone in a Different Database Table in Java/Spring/Hibernate

My goal is我的目标是

  1. Delete entity in current table删除当前表中的实体
  2. Clone the deleted entity to another table to store for future reference将删除的实体克隆到另一个表以存储以备将来参考

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.

相关问题 Spring 3 + Hibernate 4将数据库中的不同表加载到同一实体类中 - Spring 3 + Hibernate 4 Load different Tables from database into same entity class Spring / Hibernate同一实体不同的数据库结构 - Spring/Hibernate Same Entity different database structure 在hibernate Spring java中删除数据库中的所有对象 - Delete all objects from database in hibernate Spring java 如何从数据库加载数据并实例化实体(Hibernate和Spring) - How to load data from Database and instance the entity (Hibernate & Spring) 使用Java,Hibernate和servlet从数据库中删除行 - Delete row from database with Java, Hibernate and servlet 如何将经典sql查询的结果存储在一个没有hibernate数据库实体表的对象中? - How to Store the result of classic sql query in a object which hasn't a entity table in database with hibernate? Hibernate - 如何通过Hibernate将java.net.URL存储到数据库中 - Hibernate - How to store java.net.URL into a database through Hibernate 如何使用Hibernate将Java对象与数据库表同步 - How to synchronize a Java Object with a Database table with Hibernate 如何从Java中的数据库表中删除行 - How do I delete a row from database table in Java 如何将数据库中的表值存储在 java 的二维数组中 - how to store table values from database in a 2d array in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM