OpenJPA
  1. OpenJPA
  2. OPENJPA-210

Query returning 2 entities w/1-1 relationship returns wrong types in the result list

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.7
    • Fix Version/s: 1.0.4, 1.2.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      0.9.7-incubating-SNAPSHOT, windows, db2

      Description

      Query returning 2 entities w/1-1 relationship returns [Address, Address] instead of [Winery, Address]

      "SELECT r,r.address from Winery r" returns [Address, Address]
      "SELECT r,r.home from EmpBean r" returns [null, AddressBean]

      does not matter if 1-1 relationship is uni-directional or bi-directional

      (NOTE: "SELECT r.address,r" gets same Address id already exists in the L1 cache if uni-dir relationship (issue 209))

      clear detaches all entities from the persistent context
      1302 bugsmall TRACE [main] openjpa.Query - Executing query: SELECT r,r.home FROM EmpBean r
      1302 bugsmall TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 755379462> executing prepstmnt 335287292 SELECT t0.empid, t1.street, t1.city, t1.state, t1.zip FROM bugsmallEmpBean t0 LEFT OUTER JOIN bugsmallAddressBean t1 ON t0.home_street = t1.street
      1302 bugsmall TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 755379462> [0 ms] spent
      1302 bugsmall TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 755379462> executing prepstmnt 695216496 SELECT t0.city, t0.state, t0.zip FROM bugsmallAddressBean t0 WHERE t0.street = ? [params=(String) 1]
      1312 bugsmall TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 755379462> [10 ms] spent
      java.lang.NullPointerException
      at com.ibm.websphere.ejb3sample.winetour.bugsmall.BugSmallWineryTest.test_1_1relationshipQuery_EmpBean_AddressBean(BugSmallWineryTest.java:468)
      at com.ibm.websphere.ejb3sample.winetour.bugsmall.BugSmallWineryTest.main(BugSmallWineryTest.java:103)
      1352 bugsmall TRACE [main] openjpa.Query - Executing query: [SELECT r,r.address FROM Winery r WHERE r.wineryid = ?1] with parameters:

      {1=1}

      1352 bugsmall TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 755379462> executing prepstmnt 1670669204 SELECT t0.wineryid, t1.phone, t1.city, t1.state, t1.street, t1.zip FROM bugsmallWinery t0 LEFT OUTER JOIN bugsmallAddress t1 ON t0.address_phone = t1.phone WHERE (t0.wineryid = ?) [params=(int) 1]
      1362 bugsmall TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 755379462> [10 ms] spent
      1362 bugsmall TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 755379462> executing prepstmnt 2097052926 SELECT t0.city, t0.state, t0.street, t0.zip FROM bugsmallAddress t0 WHERE t0.phone = ? [params=(String) 1]
      1512 bugsmall TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 755379462> [0 ms] spent
      java.lang.ClassCastException: com.ibm.websphere.ejb3sample.winetour.bugsmall.Address incompatible with com.ibm.websphere.ejb3sample.winetour.bugsmall.Winery
      at com.ibm.websphere.ejb3sample.winetour.bugsmall.BugSmallWineryTest.test_1_1relationshipQuery_Winery_Address(BugSmallWineryTest.java:374)
      at com.ibm.websphere.ejb3sample.winetour.bugsmall.BugSmallWineryTest.main(BugSmallWineryTest.java:104)
      close(only used for application managed Persistent Context) inactivates the EntityManager and detaches all entities
      create new Application Managed Persistent Context with no managed entities

      ====================================
      Starting test_1_1relationshipQuery_EmpBean_AddressBean()
      ====================================
      Shows a EmpBean and its address
      String sql = "SELECT r,r.home FROM EmpBean r WHERE r.empid = ?1"
      Caution: requires _em.find(EmpBean.class,parm1) to avoid cache exception or incorrect types in result list
      Caution: "SELECT r,r.home" currently fails, returns [null, AddressBean] instead of [EmpBean, AddressBean]
      -----------------------------------------------------------------------------
      1-1 query oa[0] is null
      1-1 query oa[1] = com.ibm.websphere.ejb3sample.winetour.bugsmall.AddressBean

      ====================================
      Starting test_1_1relationshipQuery_Winery_Address()
      ====================================
      Shows a winery and its address
      String sql = "SELECT r,r.address FROM Winery r WHERE r.wineryid = :wineryid "
      Caution: requires _em.find(Winery.class,parm1) to avoid cache exception or incorrect types in result list
      Caution: "SELECT r,r.address" currently fails, returns [Address, Address] instead of [Winery, Address]
      -----------------------------------------------------------------------------
      1-1 query oa[0] = com.ibm.websphere.ejb3sample.winetour.bugsmall.Address
      1-1 query oa[1] = com.ibm.websphere.ejb3sample.winetour.bugsmall.Address

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        461d 15h 6m 1 Pinaki Poddar 11/Jul/08 15:33
        Resolved Resolved Closed Closed
        606d 3h 58m 1 Donald Woods 09/Mar/10 18:32
        Donald Woods made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Pinaki Poddar made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Pinaki Poddar added a comment -

        Consider not deferring.
        Resolved with r666515 (2008-06-10).

        Show
        Pinaki Poddar added a comment - Consider not deferring. Resolved with r666515 (2008-06-10).
        Michael Dick made changes -
        Fix Version/s 1.0.4 [ 12313301 ]
        Fix Version/s 1.0.3 [ 12312969 ]
        Hide
        Michael Dick added a comment -

        Defer to next release.

        Show
        Michael Dick added a comment - Defer to next release.
        Patrick Linskey made changes -
        Fix Version/s 1.2.0 [ 12313102 ]
        Fix Version/s 1.1.0 [ 12312344 ]
        Patrick Linskey made changes -
        Fix Version/s 1.0.2 [ 12312846 ]
        Fix Version/s 1.1.0 [ 12312344 ]
        Fix Version/s 1.0.3 [ 12312969 ]
        Albert Lee made changes -
        Fix Version/s 1.0.2 [ 12312846 ]
        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.
        Marc Prud'hommeaux made changes -
        Fix Version/s 1.0.0 [ 12312341 ]
        Fix Version/s 1.0.1 [ 12312687 ]
        Hide
        Marc Prud'hommeaux added a comment -

        Bumping to release 1.0.1 since 1.0.0 is being released.

        Show
        Marc Prud'hommeaux added a comment - Bumping to release 1.0.1 since 1.0.0 is being released.
        Hide
        Kevin Sutter added a comment -

        Some of the problems identified in this Issue sound very similar to other problems that I am currently driving. I'll take a look at this Issue and see where it goes.

        Show
        Kevin Sutter added a comment - Some of the problems identified in this Issue sound very similar to other problems that I am currently driving. I'll take a look at this Issue and see where it goes.
        Kevin Sutter made changes -
        Assignee Kevin Sutter [ kwsutter ]
        Craig L Russell made changes -
        Affects Version/s 0.9.7 [ 12312340 ]
        Fix Version/s 1.0.0 [ 12312341 ]
        Hide
        George Hongell added a comment -

        The same test on a similar application fails with java.lang.InstantiationException: java.lang.Integer
        String sql = "SELECT r,r.home FROM EmpBean r";

        clear detaches all entities from the persistent context
        2463 mdd TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 1297894748> executing prepstmnt 96339390 SELECT t0.empid, t1.street, t1.city, t1.state, t1.zip FROM EmpBean t0 LEFT OUTER JOIN AddressBean t1 ON t0.home_street = t1.street
        2463 mdd TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 1297894748> [0 ms] spent
        <0|false|0.9.7-incubating-SNAPSHOT> org.apache.openjpa.persistence.PersistenceException: java.lang.Integer
        at org.apache.openjpa.util.ApplicationIds.copy(ApplicationIds.java:301)
        at org.apache.openjpa.util.ApplicationIds.copy(ApplicationIds.java:239)
        at org.apache.openjpa.kernel.StateManagerImpl.initialize(StateManagerImpl.java:236)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:327)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:252)
        at org.apache.openjpa.kernel.DelegatingStoreManager.initialize(DelegatingStoreManager.java:108)
        at org.apache.openjpa.kernel.ROPStoreManager.initialize(ROPStoreManager.java:54)
        at org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:873)
        at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:831)
        at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:753)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:773)
        at org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:254)
        at org.apache.openjpa.jdbc.sql.SelectImpl$SelectResult.load(SelectImpl.java:2115)
        at org.apache.openjpa.jdbc.kernel.exps.PCPath.load(PCPath.java:684)
        at org.apache.openjpa.jdbc.kernel.exps.PCPath.load(PCPath.java:672)
        at org.apache.openjpa.jdbc.kernel.ProjectionResultObjectProvider.getResultObject(ProjectionResultObjectProvider.java:73)
        at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:33)
        at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1214)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:981)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:791)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:761)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:757)
        at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:512)
        at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:225)
        at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:264)
        at com.ibm.ws.query.tests.BugTest.test_1_1relationshipQuery_EmpBean_AddressBean(BugTest.java:252)
        at com.ibm.ws.query.tests.BugTest.main(BugTest.java:96)
        Caused by: java.lang.InstantiationException: java.lang.Integer
        at java.lang.Class.newInstanceImpl(Native Method)
        at java.lang.Class.newInstance(Class.java:1243)
        at org.apache.openjpa.util.ApplicationIds.copy(ApplicationIds.java:299)
        ... 26 more
        close(only used for application managed Persistent Context) inactivates the EntityManager and detaches all entities
        create new Application Managed Persistent Context with no managed entities

        ====================================
        Starting test_1_1relationshipQuery_EmpBean_AddressBean()
        ====================================
        Shows a EmpBean and its address
        String sql = "SELECT r.home,r FROM EmpBean r WHERE r.empid = ?1"
        Caution: requires _em.find(EmpBean.class,parm1) to avoid cache exception
        Caution: "SELECT r,r.home" currently fails, returns [AddressBean, AddressBean] instead of [EmpBean, AddressBean]
        -----------------------------------------------------------------------------

        Show
        George Hongell added a comment - The same test on a similar application fails with java.lang.InstantiationException: java.lang.Integer String sql = "SELECT r,r.home FROM EmpBean r"; clear detaches all entities from the persistent context 2463 mdd TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 1297894748> executing prepstmnt 96339390 SELECT t0.empid, t1.street, t1.city, t1.state, t1.zip FROM EmpBean t0 LEFT OUTER JOIN AddressBean t1 ON t0.home_street = t1.street 2463 mdd TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 1297894748> [0 ms] spent <0|false|0.9.7-incubating-SNAPSHOT> org.apache.openjpa.persistence.PersistenceException: java.lang.Integer at org.apache.openjpa.util.ApplicationIds.copy(ApplicationIds.java:301) at org.apache.openjpa.util.ApplicationIds.copy(ApplicationIds.java:239) at org.apache.openjpa.kernel.StateManagerImpl.initialize(StateManagerImpl.java:236) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:327) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:252) at org.apache.openjpa.kernel.DelegatingStoreManager.initialize(DelegatingStoreManager.java:108) at org.apache.openjpa.kernel.ROPStoreManager.initialize(ROPStoreManager.java:54) at org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:873) at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:831) at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:753) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:773) at org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:254) at org.apache.openjpa.jdbc.sql.SelectImpl$SelectResult.load(SelectImpl.java:2115) at org.apache.openjpa.jdbc.kernel.exps.PCPath.load(PCPath.java:684) at org.apache.openjpa.jdbc.kernel.exps.PCPath.load(PCPath.java:672) at org.apache.openjpa.jdbc.kernel.ProjectionResultObjectProvider.getResultObject(ProjectionResultObjectProvider.java:73) at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:33) at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1214) at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:981) at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:791) at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:761) at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:757) at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:512) at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:225) at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:264) at com.ibm.ws.query.tests.BugTest.test_1_1relationshipQuery_EmpBean_AddressBean(BugTest.java:252) at com.ibm.ws.query.tests.BugTest.main(BugTest.java:96) Caused by: java.lang.InstantiationException: java.lang.Integer at java.lang.Class.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1243) at org.apache.openjpa.util.ApplicationIds.copy(ApplicationIds.java:299) ... 26 more close(only used for application managed Persistent Context) inactivates the EntityManager and detaches all entities create new Application Managed Persistent Context with no managed entities ==================================== Starting test_1_1relationshipQuery_EmpBean_AddressBean() ==================================== Shows a EmpBean and its address String sql = "SELECT r.home,r FROM EmpBean r WHERE r.empid = ?1" Caution: requires _em.find(EmpBean.class,parm1) to avoid cache exception Caution: "SELECT r,r.home" currently fails, returns [AddressBean, AddressBean] instead of [EmpBean, AddressBean] -----------------------------------------------------------------------------
        George Hongell made changes -
        Field Original Value New Value
        Attachment 1_1WrongReturnTypesBugWineryTest.zip [ 12355112 ]
        Hide
        George Hongell added a comment -

        run main method of BugSmallWineryTest in attached application to reproduce error

        Show
        George Hongell added a comment - run main method of BugSmallWineryTest in attached application to reproduce error
        George Hongell created issue -

          People

          • Assignee:
            Kevin Sutter
            Reporter:
            George Hongell
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development