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

Option for injecting empty (non-null) embedded when all columns are NULL

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

Status

Assignee

Guillaume Smet

Reporter

Ondra Žižka

Labels

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

4.1.7

Priority

Major