1

我有Set<Reference>像这样映射的可嵌入类。

@ElementCollection
@ForeignKey(name = "fk_object_org_ref")
@CollectionTable(name = "m_object_org_ref", joinColumns = {
    @JoinColumn(name = "object_oid", referencedColumnName = "oid"),
    @JoinColumn(name = "object_id", referencedColumnName = "id") })
@Cascade({ org.hibernate.annotations.CascadeType.ALL })
public Set<Reference> getParentOrgRef() {
    return parentOrgRef;
}

参考映射如下:

@Embeddable
public class Reference implements Serializable {

    @Column(length = 36, insertable = true, updatable = true, nullable = true)
    public String getTargetOid() {
        return targetOid;
    }

    @Lob
    @Type(type = "org.hibernate.type.TextType")
    public String getDescription() {
        return description;
    }

    @Enumerated(EnumType.ORDINAL)
    public RContainerType getType() {
        return type;
    }

    @Lob
    @Type(type = "org.hibernate.type.TextType")
    public String getFilter() {
        return filter;
    }
    ...other methods/fields...
}

当我尝试合并父实体(例如,我从集合中删除一个引用)时,hibernate 在合并期间将此 sql 生成为准备好的语句...

delete from reference where object_id=? and object_oid=? and description=? and filter=? and localPart=? and namespace=? and targetOid=? and type=?

但是如果例如描述是NULL那么这个删除失败,更确切地说它不会删除记录,因为 where 子句不好(description=null正确的方法是description is null)。那么我怎么能告诉hiberate它应该创建“更好”的sql删除呢?

它仅在所有字段都具有非空值时才有效。

4

0 回答 0