OpenJPA
  1. OpenJPA
  2. OPENJPA-329

Generic interface may cause the openjpa Reflection code to pickup the wrong getter method

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.2, 1.1.0
    • Component/s: jpa
    • Labels:
      None

      Description

      The test case

      public void testFind()

      { PersistenceProviderImpl openJPA = new PersistenceProviderImpl(); EntityManagerFactory factory = openJPA.createEntityManagerFactory("test", "ptp/test/issue6/persistence.xml", System.getProperties() ); EntityManager em = factory.createEntityManager(); em.getTransaction().begin(); String query="select obj from T6Entity obj where obj.name=?1"; Query queryObject = em.createQuery(query); queryObject.setParameter(1, "Mom"); List resultList = queryObject.getResultList(); em.getTransaction().commit(); em.close(); }

      produces the following exception

      <1.0.0-SNAPSHOT-SNAPSHOT fatal user error> org.apache.openjpa.persistence.ArgumentException: Collection field "ptp.test.issue6.T6Entity.children" declares that it is mapped by "ptp.test.issue6.T6Entity.parent", but this is not a valid inverse relation.
      at org.apache.openjpa.jdbc.meta.MappingRepository.useInverseKeyMapping(MappingRepository.java:903)
      at org.apache.openjpa.jdbc.meta.MappingRepository.defaultTypeStrategy(MappingRepository.java:838)
      at org.apache.openjpa.jdbc.meta.MappingRepository.defaultStrategy(MappingRepository.java:771)
      at org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:62)

      public interface ITree <T extends ITree> {
      public List<T> getChildren();
      public T getParent();
      }

      public class T6Entity implements ITree {

      private Long id;
      T6Entity parent;
      List<T6Entity> children;

      public T6Entity getParent()

      { return parent; }

      public Long getId()

      { return id; }

      public void setId(Long id)

      { this.id = id; }

      public List<T6Entity> getChildren()

      { return children; }

      public void setChildren(List<T6Entity> children)

      { this.children = children; }

      public void setParent(T6Entity parent)

      { this.parent = parent; }

      public void addChild(T6Entity aChild) {
      if ( children == null )

      { children = new ArrayList<T6Entity>(); }

      children.add( aChild );
      aChild.setParent(this);
      }

      }

      <entity class="T6Entity">
      <table name="T6Entity" />
      <attributes>
      <id name="id">
      <column name="S_ID" />
      <generated-value strategy="SEQUENCE" generator="seqGen1" />
      <sequence-generator name="seqGen1" sequence-name="SEQ_OBJECT_ID" />
      </id>

      <many-to-one name="parent" fetch="EAGER">
      <join-column name="PARENT_ID" />
      <cascade>
      <cascade-persist />
      <cascade-merge />
      </cascade>
      </many-to-one>
      <one-to-many name="children"
      target-entity="T6Entity"
      mapped-by="parent" fetch="LAZY">
      <cascade>
      <cascade-persist />
      <cascade-merge />
      </cascade>
      </one-to-many>
      </attributes>
      </entity>

      The java compiler generate the following 2 method for getParent()

      public volatile ptp.test.issue6.ITree ptp.test.issue6.T6Entity.getParent()
      public ptp.test.issue6.T6Entity ptp.test.issue6.T6Entity.getParent()

      and depending on the order of the methods return from the reflection getDeclaredMethod(), it cause the wrong return type to be infer as the inverse relationship.

      There is a work around, by specifying the target-entity in the many-to-one mapping.

      But may be something that should be fix.

        Issue Links

          Activity

          Henry Lai created issue -
          Hide
          Henry Lai added a comment -

          files to reproduce bug

          Show
          Henry Lai added a comment - files to reproduce bug
          Henry Lai made changes -
          Field Original Value New Value
          Attachment ptpissue6.zip [ 12364363 ]
          Hide
          Marc Prud'hommeaux added a comment -

          Bumping to 1.0.1 since 1.0.0 is released.

          Show
          Marc Prud'hommeaux added a comment - Bumping to 1.0.1 since 1.0.0 is released.
          Marc Prud'hommeaux made changes -
          Fix Version/s 1.0.0 [ 12312341 ]
          Fix Version/s 1.0.1 [ 12312687 ]
          Hide
          Albert Lee added a comment -

          Defer to next release.

          Show
          Albert Lee added a comment - Defer to next release.
          Albert Lee made changes -
          Fix Version/s 1.0.1 [ 12312687 ]
          Fix Version/s 1.0.2 [ 12312846 ]
          Patrick Linskey made changes -
          Link This issue relates to OPENJPA-251 [ OPENJPA-251 ]
          Hide
          Patrick Linskey added a comment -

          I didn't run the reproducer directly, but created a unit test case that I believe accurately addresses the issue. The next snapshot 1.0.2 build will include this change.

          Show
          Patrick Linskey added a comment - I didn't run the reproducer directly, but created a unit test case that I believe accurately addresses the issue. The next snapshot 1.0.2 build will include this change.
          Patrick Linskey made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Patrick Linskey made changes -
          Fix Version/s 1.1.0 [ 12312344 ]
          Donald Woods made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Henry Lai
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development