I have Set<Reference>
with embeddable class in it mapped like this.
@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;
}
Reference is mapped like this:
@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...
}
When I try to merge parent entity (for example I remove one reference from set), hibernate generates this sql as prepared statement during merge...
delete from reference where object_id=? and object_oid=? and description=? and filter=? and localPart=? and namespace=? and targetOid=? and type=?
but if for example description was NULL
then this delete fails, more exactly it doesn't delete record because where clause is not good (description=null
, proper way is description is null
). So how can I tell hiberate that it should create "better" sql delete?
It works only if all fields have non null values.