Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2559

OpenJPA silently ignores assigning a null value to a non-nullable column

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.3.0
    • None
    • kernel
    • None

    Description

      OpenJPA should throw a PersistenceException when you merge an entity that has null for a field that is mapped to a non-nullable column (@Column(nullable = false)). This should also happen when you set the field to null for an attached entity and then commit the change.

      This works fine for entities that haven't been persisted yet (INSERT). However this does NOT happen for entities that are already persistent with a non-null value for the field (UPDATE). When doing entityManager.merge, the returned entity has null for the field, but the database still has the old value. The entity returned by entityManager.find also returns this old non-null value. Similarly, after setting the field to null on an attached entity and committing the transaction it is still null in the entity, but not in the database.

      This behavior makes it a lot harder to detect programming errors where you accidentally attempt to update a non-nullable column to null, or where you made a mistake in the mapping and actually expected the column to be nullable. (Unless you also use the JSR 303 @NotNull annotation.)

      Attachments

        1. NonNullableColumnTest.java
          4 kB
          Vermeulen
        2. NonNullable.java
          0.5 kB
          Vermeulen

        Issue Links

          Activity

            People

              Unassigned Unassigned
              slowstrider Vermeulen
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: