Uploaded image for project: 'Hibernate ORM'
  1. Hibernate ORM
  2. HHH-7610

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

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.1.7
    • Fix Version/s: 5.1.0
    • Component/s: hibernate-core
    • Labels:
    • Environment:
      JBoss EAP 6.0.1.ER1
    • Last commented by a user?:
      true

      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.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                32 Vote for this issue
                Watchers:
                26 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: