Quote:
Like all value types, components do not support shared references. The null value semantics of a component are ad hoc. When reloading the containing object, Hibernate will assume that if all component columns are null, then the entire component is null. This should be okay for most purposes.
This is not okay when I try to populate my mapped object, which contains a component with columns that are null, from the front-end with e.g. <spring:bind/> tags. The BeanWrapper underneath throws an exception because the underlying components has not been initialized.
Code:
BeanWrapper wrapper = new BeanWrapperImpl(form);
wrapper.setPropertyValue("p1.nom","Joe Tester");
assertEquals("Joe Tester",form.getP1().getNom());
failsIs instantiating the components within the mapped class's private fields the recommended way to avoid this problem? Like this:
Code:
public class Form
{
private P p1 = new P();
private P p2 = new P();
private P p3 = new P();
/**
* @hibernate.component
* prefix="P1_"
*/
public final P getP1()
{
return p1;
}
public final void setP1(P p1)
{
this.p1 = p1;
}
...
Any other solutions?