openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fay Wang <fyw...@yahoo.com>
Subject Re: openjpa-2.0 how join fetch work?
Date Tue, 01 Jun 2010 16:09:36 GMT
Hi,
   I could not reproduce this problem. In my test case, the Customer and Order is 1-m relationship:

    @OneToMany(cascade = ALL/, mappedBy = "customer")
    private Collection<Order> orders = new ArrayList<Order>();

The following query works just fine:

         Query q = em.createQuery("SELECT c FROM Customer c JOIN FETCH c.orders where c.name
= 'c1'");
        List<Customer> list = q.getResultList();


Can you post your Corporation.java and Division.java?

Regards,
Fay



----- Original Message ----
From: Zhanming Qi <opengloves@gmail.com>
To: users@openjpa.apache.org
Sent: Mon, May 31, 2010 6:10:01 AM
Subject: openjpa-2.0 how join fetch work?


Hi,

I have two Entity, Corporation and Division, a simple one to many relation.

@Test
public void testQueryFetchJoins(){
    EntityManager em = entityManagerProvider.get();
    Query query = em.createQuery(
            "SELECT c " +
            "    FROM Corporation c JOIN FETCH c.divisions " +
            "    WHERE c.name = '" + CORP_A_NAME + "'");
    List<Corporation> result = query.getResultList();
    for (Corporation corporation : result ){
        System.out.println(corporation.getName());  
    }
    em.clear();
}

I test this method, and it print the right SQL Script on console.
but the test does not pass.

This is the failure trace:

<openjpa-2.0.0-r422266:935683 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: null
FailedObject: SELECT c     FROM Corporation c JOIN FETCH c.divisions     WHERE
c.name = 'Corporation A' [java.lang.String]
    at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:986)
    at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:885)
    at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:1050)
    at org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:280)
    at
org.apache.openjpa.jdbc.sql.SelectImpl$SelectResult.load(SelectImpl.java:2344)
    at org.apache.openjpa.jdbc.sql.AbstractResult.load(AbstractResult.java:274)
    at
org.apache.openjpa.jdbc.kernel.InstanceResultObjectProvider.getResultObject(InstanceResultObjectProvider.java:59)
    at
org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
    at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1246)
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:861)
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:792)
    at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
    at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:288)
    at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
    at
com.qizm.tutorial.jpa.model.CorporationTest.testQueryFetchJoins(CorporationTest.java:210)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
    at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.setInverseRelation(JDBCStoreManager.java:489)
    at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:449)
    at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:342)
    at
org.apache.openjpa.kernel.DelegatingStoreManager.initialize(DelegatingStoreManager.java:112)
    at
org.apache.openjpa.kernel.ROPStoreManager.initialize(ROPStoreManager.java:57)
    at org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:1005)
    at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:963)
    ... 38 more

Here is the openjpa.Log
1672  aUnit  TRACE  [main] openjpa.jdbc.SQL - <t 24512621, conn 2310757>
executing prepstmnt 28730188 
SELECT t0.ID, t0.version, t0.CORPORATION_NAME, t1.CORPORATION_ID, t1.ID, 
        t1.version, t1.CITY, t1.STATE, t1.STREET, t1.ZIP_CODE, t1.mumber, 
        t1.name 
    FROM CORPORATION t0 INNER JOIN DIVISION t1 ON t0.ID = t1.CORPORATION_ID 
    WHERE (t0.CORPORATION_NAME = ?) 
[params=(String) Corporation A]

This SQL is right, but how did I can not pass this:List<Corporation> result
= query.getResultList();

Thanks.
Zhanming
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/openjpa-2-0-how-join-fetch-work-tp5121731p5121731.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.



      


Mime
View raw message