It would be useful to have a way to express that we want the component object to be an empty object (new Address()) instead of null when all the component fields are null.
In my specific use case, I am using Spring MVC to bind form data values to the domain classes and I have something like
Code:
<spring:bind path="companyForm.company.address.city">
<input name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" />
</spring:bind>
In my Company class, is specifically declare the Address member as
Code:
class company {
private Address address = new Address();
However since objects loaded from Hibernate set the address composite member to null, I end up getting NullPointerExceptions.
With hibernate setting the component member to null despite me having declared the address member as new Address() I now have an inconsistency introduced.
Using a user type for this is going to be complex as my current component has 'many-to-one' declarations which is nicely handled by hibernate when using a 'component'. Using a User type for handling a many-to-one mapping would require the UserType implrmentation to query the database and replicate logic that hibernate already handles.
Thanks,
Sanjiv