When using a mapping that contains a dynamic-component, if an entity is persisted where all the entries of the component are null, when the entity is loaded hibernate sets the entire component map to null.
Is this the expected behaviour? Is there a reason that an empty HashMap is not used instead?
Hibernate version: 3.0rc1-3.0cvs20050324
Mapping document:
Code:
<hibernate-mapping>
<class name="eg.Bean" table="BEANS">
<id name="id" column="BEANID" type="integer">
<generator class="native"/>
</id>
<dynamic-component name="properties">
<property name="test01" column="TEST01" type="string" length="64"/>
</dynamic-component>
</class>
</hibernate-mapping>
Java files:Code:
public class Bean {
private Integer id;
private Map properties = new HashMap();
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
public Map getProperties() { return properties; }
public void setProperties(Map properties) {
if (properties == null)
throw new IllegalArgumentException("Why should I be nulled?");
this.properties = properties;
}
}
Code:
public class Test {
public static void main(String[] args) {
Configuration cfg = new Configuration().configure();
new SchemaExport(cfg).create(false, true);
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
s = sf.openSession();
Bean b = new Bean();
s.save(b);
s.flush();
s.close();
Integer id = b.getId();
s = sf.openSession();
b = (Bean) s.get(Bean.class, id); //This will set properties to null
}
}