我无法使用@EmbeddedId执行软删除吗? @SQLDelete中的sql未执行。
我试图对两个ID的值进行硬编码以构成嵌入式ID。
我可以仅使用@Id而不使用@Id进行实体的软删除实现 @EmbeddedId
当我对只有@Id的实体执行delete测试时,我可以看到在控制台上执行的是sql,但是没有@EmbeddedId。
我认为它只是绕过@SQLDelete并使用来自休眠的默认删除sql。 我期望@SQLDelete中的sql被执行。
@Data
@EqualsAndHashCode(exclude = "serviceEmployeeIdentity", callSuper = true)
@Entity
@Audited
@Table(name = "service_employee")
@SQLDelete(sql = "UPDATE service_employee " +
"SET deleted = true " +
"WHERE service_employee.service_id = ?1 " +
"AND service_employee.employee_b_number = ?2")
@Where(clause = "deleted = false")
public class ServiceEmployee extends Auditable implements Serializable {
@EmbeddedId
private ServiceEmployeeIdentity serviceEmployeeIdentity;
@Column(name = "critical")
private Boolean critical;
@Column(name = "critical_rationale")
private String criticalRationale;
}
@Repository
public interface ServiceEmployeeRepository extends
JpaRepository<ServiceEmployee, ServiceEmployeeIdentity> {}
// test
ServiceEmployee serviceEmployee = ServiceEmployeeBuilder.aServiceEmployee();
serviceEmployeeService.deleteById(
serviceEmployee.getServiceEmployeeIdentity());
注意: serviceEmployee已设置了EmbeddedId serviceEmployeeService只是调用存储库类
答案 0 :(得分:0)
这将像它是单值@Id
带注释的列一样工作。您只需要按照嵌入式类中它们表示的顺序指定多个列,因此可以在您的@SQLDelete
中使用它:
UPDATE service_employee
SET deleted = true
WHERE service_id = ?
AND employee_b_number = ?
答案 1 :(得分:0)
我为我努力工作,但是顺序是EmbeddedId列的字母顺序
document.getElementById("smile").src = "smiley.gif"
如果我使用
@SQLDelete(sql = "UPDATE (table_name) SET DELETED=true WHERE event_id = ? and payment_id=?")
它将不起作用,并且不会更新所需的寄存器。