OpenJPA
  1. OpenJPA
  2. OPENJPA-2157

@SecondaryTable configuration does not handle @ManyToOne foreign keys properly

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1.1, 2.2.0
    • Fix Version/s: None
    • Component/s: jpa, tooling
    • Labels:
      None

      Description

      @ManyToOne @JoinColumn(name = "f_key", table = "SEC_TABL") schema tool ignores the name specified, auto-generate a name for the join column. Worse, when deleting the entity, NPE is thrown. There may also other effects. Here is the NPE stack trace in 2.2.0 version.

      Caused by: java.lang.NullPointerException
      at org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.delete(RelationFieldStrategy.java:412)
      at org.apache.openjpa.jdbc.meta.FieldMapping.delete(FieldMapping.java:704)
      at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.delete(AbstractUpdateManager.java:287)
      at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:166)
      at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:95)
      at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:713)
      at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
      at org.apache.openjpa.datacache.DataCacheStoreManager.flush(DataCacheStoreManager.java:661)
      at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
      at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2174)
      at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2072)
      at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1843)
      ... 39 more

      Sample Entities (Only relevant parts, HUMAN table won't have mother_id and father_id but auto-generated MOTHER_RECORD_ID and FATHER_RECORD_ID):
      ----------------------------

      @javax.persistence.Entity
      @Table(name = "LIVING")
      @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
      @DiscriminatorColumn(name = "dtype")
      public class Living

      { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "record_id") private long systemId = 0L; @Version @Column(name = "version") private long version = 0; }

      @javax.persistence.Entity
      @SecondaryTable(name = "HUMAN", pkJoinColumns = @PrimaryKeyJoinColumn(name = "record_id"))
      public class Human extends Living

      { @ManyToOne @JoinColumn(name = "mother_id", table = "HUMAN") private Human mother; @ManyToOne @JoinColumn(name = "father_id", table = "HUMAN") private Human father; }

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            Kemal Serkan
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development