We're updating the issue view to help you get more done. 

Introduce an annotation to disable ad-hoc null semantic of Hibernate components

Description

see http://forums.hibernate.org/viewtopic.php?t=993972

For the model

@Entity
public class Person {
private Address name = new Address();
...
@Embedded Address getAddress() {}
}

@Embeddable
public class Address {
public String getCity() {}
public String getStreet() {}
}

the following xhtml excerpt causes NPE constantly when editing a person which address properties hasn't been filled in yet

<h:inputText value="#{person.address.city}" />

I suggest introducing an annotation @Static which could be applied to Address class and lead to disabling null ad-hoc semantic on its instances.

For some environments such as user interface this may be considered as the default behavior. I suggest introducing an Hibernate configuration parameter which would switch off the semantic.

I would propose to consider embeddable classes as static mixins from OO design, not as just limited entities without identity. This point of view explains that embedded instance is a part of entity so it's lifecycle is the same as the entity's lifecycle. Thus constant presence of embeddable instance (property is never null) is the default behavior. Thus configuration parameter is "must have", not the thing which is "nice to have".

From the other hand null ad-hoc semantic is like dynamic mixins. So it would be nice to have a @Dynamic annotation to force this semantic for some components.

Environment

None

Status

Assignee

Unassigned

Reporter

VladimirV

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major