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

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


    • 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?:
    • Sprint:


      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.


          Issue links



              • Votes:
                32 Vote for this issue
                27 Start watching this issue


                • Created: