How to @SQLDelete, soft delete, entity with a composite key

Viewed 305

how to obtain pieces of composite key in @SQLDelete to perform soft deletion of an entity?

@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;
}
1 Answers

Values of the composite ID are bound to the prepared statement in the order of the properties of the IdClass, so this should work:

@SQLDelete(sql = "UPDATE dummy SET deleted = 'Y' WHERE foo=? AND bar=?")

(The AbstractEntityPersister delegates the binding to the identifier type, so in this case to ComponentType which iterates over the properties with help of an AbstractComponentTuplizer)

Related