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

Default join table column name in many-to-many relationship does not follow JPA v2 specification

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.1.1
    • None
    • jdbc, jpa
    • None

    Description

      According to JPA v2 specification page 48, the joining table should have two columns. One column should have foreign key to owners table and the other should have foreign key to the inverse table.

      The name of the column referencing the owner should be:

      • the name of the relationship property or field of inverse entity ;
      • underscore "_";
      • the name of the primary key column in owner table.

      OpenJPA assumes that the name of the column referencing the owner is:

      • owner entity name ;
      • underscore "_";
      • the name of the primary key column in owner table.

      The name of the column referencing the inverse is correct.

      Example entities:
      @Entity
      @Table(name="tblMtmOwner")
      public class MtmOwner {
      @Id
      private long id;
      private String name;
      @ManyToMany
      private Collection<MtmInverse> inverses = new ArrayList<MtmInverse>();
      }

      @Entity
      public class MtmInverse{
      @Id
      private long id;
      @ManyToMany(mappedBy="inverses")
      @MapKey(name="name")
      private Map<String, MtmOwner> owners = new HashMap<String, MtmOwner>();
      }

      Expected column name: owners_id
      OpenJPA column name: mtmowner_id

      Attachments

        Activity

          People

            Unassigned Unassigned
            meri Maria Jurcovicova
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: