java code:
Although it seems that the problem is represented in UI it is actually caused by the ad-hoc null semantic of Hibernate components.
Code:
@Entity
public class Person {
private Address name = new Address();
...
@Embedded Address getAddress() {}
}
@Embeddable
public class Address {
public String getCity() {}
public String getStreet() {}
}
xhtml:
<h:inputText value="#{person.address.city}" />
This code produces NPE constantly when editing a person which address properties hasn't been filled in yet.
If I set address instance before person is accessed when rendering it will force dirty checking and even I hasn't changed any property the person instance itself will be updated and its version incremented.
Moreover it would cause pre-update events. Whether events are invoked would depends on data. It is unacceptable.
If I add a fake primitive propery to every Embeddable object it would cause Exception (writing null to not-null property) when loading the Object. Although some forums suggest it as workaround it does not work for me.
So I'm asking experienced Hibernate users to suggest me an advice what to do with that?