如何获取@SQLDelete
中的复合键片段来执行实体的软删除?
@Data
class DummyKey {
private Long foo;
private Long bar;
}
@IdClass(DummyKey.class)
@SQLDelete(sql = "UPDATE dummy SET deleted = 'Y' WHERE ???") //how to get key params
@Where(clause = "deleted='N'")
class Dummy {
@Id
@Column(name = "foo")
private Long foo;
@Id
@Column(name = "bar")
private Long bar;
@Column(name = "stuff")
private String stuff;
@Column(name = "deleted")
private String deleted;
}
最佳答案
复合 ID 的值按照 IdClass
属性的顺序绑定(bind)到准备好的语句,因此这应该有效:
@SQLDelete(sql = "更新虚拟集已删除 = 'Y' WHERE foo=? AND bar=?")
( AbstractEntityPersister
将绑定(bind)委托(delegate)给标识符类型,因此在本例中为 ComponentType
,它在 AbstractComponentTuplizer
的帮助下迭代属性)
关于java - 如何@SQLDelete、软删除、具有组合键的实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68130548/