1. OpenJPA
  2. OPENJPA-393

@Column(nullable=false) setting not taken into account for String field values


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0
    • Fix Version/s: 1.2.0
    • Component/s: None
    • Labels:
    • Environment:
      Linux 2.6, Java JDK, Spring 2.0.7


      The @Column(nullable=false) annotation is taken into account when creating the database schema, however it is not taken into account when inserting string values.

      See the following test case:
      public class A {

      private long id;

      private String name;

      public A() {}

      public A(String name)

      { = name; }

      [...accessor methods omitted...]

      When trying to persist the instance A(null), the record will be created successfully with an empty string as the value of the name column, instead of returning an error.

      According to my analysis the problem is the following. When the @Column annotations are parsed (see AnnotationPersistenceMappingParser) the FieldMapping.setNullValue() method is not called. As a result, when fetching the String field value for storing it in the database the default value for strings is returned (which is an empty string), instead of raising an exception. See StringFieldStrategy.toDataStoreValue() for reference.

      The proposed solution would be to call this setNullValue method with the appropriate parameter while @Column annotations are parsed, but I don't know the OpenJPA source well enough to determine whether this is the proper fix or if there are other parameters that should be set in the FieldMapping. However, my local tests fixed the reported issue.

        Issue Links


          Gergely Kis created issue -
          Pinaki Poddar made changes -
          Field Original Value New Value
          Link This issue duplicates OPENJPA-665 [ OPENJPA-665 ]
          Pinaki Poddar made changes -
          Assignee Pinaki Poddar [ ]
          Pinaki Poddar made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Michael Dick made changes -
          Fix Version/s 1.2.0 [ 12313102 ]
          Donald Woods made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          296d 19h 33m 1 Pinaki Poddar 29/Jul/08 18:42
          Resolved Resolved Closed Closed
          587d 23h 49m 1 Donald Woods 09/Mar/10 18:32


            • Assignee:
              Pinaki Poddar
              Gergely Kis
            • Votes:
              1 Vote for this issue
              0 Start watching this issue


              • Created: