设置可嵌入,可空的属性

时间:2012-11-30 23:06:28

标签: java hibernate annotations set embeddable

我在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...
}

当我尝试合并父实体时(例如我从set中删除一个引用),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 delete?

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

0 个答案:

没有答案