我正在使用 JDBC 将 JPA api detach 迁移到纯 SQL,我发现很难理解 EntityManager.detach(someTask) 的概念。
我尝试使用删除查询进行分离,但它似乎一次从数据库中删除了整个记录。
@Entity
@Table(name = "TASK", indexes = {@Index(name = "RIO", columnList = "priority", unique = false),
@Index(name = "EXP", columnList = "expiry", unique = false),
@Index(name = "STA", columnList = "taskStatus", unique = false),
@Index(name = "CAT", columnList = "category", unique = false),
@Index(name = "NEXTTRY", columnList = "nextTry", unique = false)})
public class TaskEntity {
@Version
private int version;
@Basic
@Column(length = Integer.MAX_VALUE, columnDefinition = "varchar(" +
Integer.MAX_VALUE + ")")
private String taskId;
@Basic
private String category;
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "KEY")
@CollectionTable(name = "TASKPROPERTIES", foreignKey = @ForeignKey(
name = "TASK_ID_FK",
foreignKeyDefinition = "FOREIGN KEY (TASKENTITY_ID) REFERENCES TASK (ID) ON DELETE CASCADE"))
@Column(length = Integer.MAX_VALUE, columnDefinition = "varchar(" +
Integer.MAX_VALUE + ")")
private Map<String, String> TaskProperties;
@Basic
@Column(length = Integer.MAX_VALUE, columnDefinition = "varchar(" +
Integer.MAX_VALUE + ")")
private String destination;
@Enumerated(EnumType.STRING)
private TaskStatus taskStatus;
@Basic
private String type;
@Basic
private Long expiry;
@Basic
private Long nextTry;
@Basic
private Integer retries;
@Basic
private Integer priority;
//Setters and Getters
//Equals and HashCode
}
很难理解分离和删除之间的区别。那么在 HSQL/SQL 中分离的等效查询是什么?