Issue Type: Improvement Improvement
Affects Versions: 4.1.7
Assignee: Unassigned
Components: core
Created: 17/Sep/12 4:38 PM
Description:

When all of the values in an @Embedded object are NULL, Hibernate sets the field in the parent object to null. This can lead to NullPointerExceptions if not handled correctly.

There are two ways to handle this:

  • Make sure code that calls the @Embedded getter handles null return values.
  • Add a non-nullable field to the embedded object, thus avoiding the behavior entirely.

I suggest to make this optional. I.e. add an annotation which would make Hibernate create an object with it's properties set to null.

In my oppinion, this would improve usability and user friendliness.
Having an embedded object with all props potentially set to null is perfectly valid use case - e.g. an object with optional traits grouped in @Embeddable class; When this is created, the traits are initially empty.

This was reported years ago as a bug, but at that time, it was closed as Won't fix for unknown reason.

Environment: JBoss EAP 6.0.1.ER1
Project: Hibernate ORM
Labels: Embedded null
Priority: Major Major
Reporter: Ondra Žižka
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira