I get a problem with Embeddable that have nullable properties. Hibernate 3.2.6.ga, Hibernate Annotations 3.3.0.ga
Code:
@Entity
public class Zone {
...
@CollectionOfElements
@JoinTable(name = "mediaholder", joinColumns = @JoinColumn(name = "zone_id"))
private Set<Mediaholder> mediaholders = new HashSet<Mediaholder>();
...
}
@Embeddable
public class Mediaholder {
private int zoneScopedId;
@Nullable
@Column(nullable = true)
private String name;
...
}
When I make
Code:
zone.mediaholders.clear();
zone.mediaholders.addAll(...);
session.saveOrUpdate(zone);
Hibernate uses a set of SQLs that update Mediaholders collection:
Code:
org.hibernate.SQL - delete from mediaholder where zone_id=? and name=? and zone_scoped_id=?
org.hibernate.type.IntegerType - binding '12' to parameter: 1
org.hibernate.type.StringType - binding null to parameter: 2
org.hibernate.type.IntegerType - binding '1' to parameter: 3
org.hibernate.SQL - insert into placeholder (zone_id, name, zone_scoped_id) values (?, ?, ?)
org.hibernate.type.IntegerType - binding '12' to parameter: 1
org.hibernate.type.StringType - binding 'some super buber place to place' to parameter: 2
org.hibernate.type.IntegerType - binding '2' to parameter: 3
When name attributes of mediaholder component are null (name is optional) that queries leads to wrong result.
Code:
delete from mediaholder where zone_id=? and name=? and zone_scoped_id=?
with one of the parameters binded as null doesn't delete any row. As I understand instead that SQL should be generated:
Code:
delete from mediaholder where zone_id=? and name IS NULL and zone_scoped_id=?
to correctly remove required record.
Is this a bug or I missed something?
Den