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

list of objects returned by query partially correct

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0.0
    • jdbc
    • None

    Description

      We have an object inheritance hierarchy as follows.

      FixedAnnuity extends Annuity
      EquityAnnuity extends Annuity

      Then we have following code:

      List<IAnnuity> annuities = getServerAdapter().findHolderAnnuities(holder);

      from which we expect to have a list of "Annuity" (could be Annuity, FixedAnnuity or
      EquityAnnuity) from following code
      EntityManager em = null;
      try

      { em = factory.createEntityManager(); Query query = em.createNamedQuery("GetHolderAnnuities"); query.setParameter("holderId", holder.getId()); return (List<IAnnuity>) query.getResultList(); }

      Here is the query
      <named-query name="GetHolderAnnuities">
      <query>SELECT a FROM Annuity AS a WHERE a.annuityHolderId = :holderId</query>
      </named-query>

      In the end, the list returned only the first object with the correct Object, the
      rest of the objects all casted into the basic type "Annuity"
      e.g. we have following code:

      EntityManager em = null;
      try{ em = factory.createEntityManager(); Query query = em.createNamedQuery("GetHolderAnnuities"); query.setParameter("holderId", holder.getId()); return (List<IAnnuity>) query.getResultList(); }

      FixedAnnuity fixed1 = new FixedAnnuity();
      fixed1.setHolder(holder);
      EquityAnnuity equity1 = new EquityAnnuity();
      equity1.setHolder(holder);
      FixedAnnuity fixed1 = new FixedAnnuity();
      fixed2.setHolder(holder);
      EquityAnnuity equity2 = new EquityAnnuity();
      equity2.setHolder(holder);

      List<IAnnuity> annuities = getServerAdapter().findHolderAnnuities(holder);

      Only annuities.get(0) returns the correct object as FixedAnnuity, the other 3
      objects returned all returned as Annuity

      Attachments

        1. jpa1.0.0.patch
          2 kB
          Catalina Wei
        2. OPENJPA-313.2.patch
          3 kB
          Catalina Wei
        3. OPENJPA-313.r564688.patch
          2 kB
          Catalina Wei
        4. OPENJPA-313.r564688.patch
          2 kB
          Catalina Wei

        Activity

          People

            Unassigned Unassigned
            fancy Catalina Wei
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: