openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kai Feng Zhang (JIRA)" <j...@apache.org>
Subject [jira] Updated: (OPENJPA-1802) Named query throws exception but normal query works
Date Wed, 13 Oct 2010 05:09:30 GMT

     [ https://issues.apache.org/jira/browse/OPENJPA-1802?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Kai Feng Zhang updated OPENJPA-1802:
------------------------------------

    Attachment: ListFieldDb.java
                EmailDb.java

Yes sure, please see new attached files.

Please let me know if you have more requirements. Thanks.

> Named query throws exception but normal query works
> ---------------------------------------------------
>
>                 Key: OPENJPA-1802
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1802
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: query
>    Affects Versions: 2.0.1
>            Reporter: Kai Feng Zhang
>         Attachments: EmailDb.java, ListFieldDb.java, PersonDb.java
>
>
> I have a named query on PersonDb entity,
> @NamedQuery(name = PersonDb.FINDBY_PERSONID, query = "select p from PersonDb p where
p.id = :id "),
> Then I use following code to get person entity:
>     Query q = entiyManager.createNamedQuery(PersonDb.FINDBY_PERSONID);
>     // Query q = entiyManager.createQuery("select p from PersonDb p where p.id = :id");
>     q.setParameter("id", uid);
>     q.setFirstResult(0);
>     q.setMaxResults(1);
>     List<?> plist = q.getResultList();
>     Person person = null;
>     if (plist != null && !plist.isEmpty()) {
>       person = (Person) plist.get(0);
>     }
> There is exception then. But if I use createQuery() as the commented line, it works,
and person is got from table.
> The exception from name query is:
> <openjpa-2.0.1-r422266:989424 nonfatal general error> org.apache.openjpa.persistence.PersistenceException:
org.apache.openjpa.util.Id cannot be cast to org.apache.openjpa.util.LongId
> FailedObject: select p from PersonDb p where p.id = :id [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:1030)
> 	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.meta.strats.RelationToManyInverseKeyFieldStrategy.loadElement(RelationToManyInverseKeyFieldStrategy.java:90)
> 	at org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStrategy.loadElement(RelationCollectionInverseKeyFieldStrategy.java:76)
> 	at org.apache.openjpa.jdbc.meta.strats.StoreCollectionFieldStrategy.load(StoreCollectionFieldStrategy.java:556)
> 	at org.apache.openjpa.jdbc.meta.FieldMapping.load(FieldMapping.java:934)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:691)
> 	at org.apache.openjpa.kernel.DelegatingStoreManager.load(DelegatingStoreManager.java:117)
> 	at org.apache.openjpa.kernel.ROPStoreManager.load(ROPStoreManager.java:78)
> 	at org.apache.openjpa.kernel.StateManagerImpl.loadFields(StateManagerImpl.java:3047)
> 	at org.apache.openjpa.kernel.StateManagerImpl.load(StateManagerImpl.java:451)
> 	at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:973)
> 	at org.apache.openjpa.kernel.BrokerImpl.find(BrokerImpl.java:885)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:1030)
> 	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.RangeResultObjectProvider.getResultObject(RangeResultObjectProvider.java:80)
> 	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 org.apache.shindig.social.opensocial.jpa.test.PersonDbToJsonTest.getJohnDoe(PersonDbToJsonTest.java:125)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	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.runChild(BlockJUnit4ClassRunner.java:76)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> 	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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> 	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	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.ClassCastException: org.apache.openjpa.util.Id cannot be cast to
org.apache.openjpa.util.LongId
> 	at org.apache.shindig.social.opensocial.jpa.ListFieldDb.pcCopyKeyFieldsFromObjectId(ListFieldDb.java)
> 	at org.apache.shindig.social.opensocial.jpa.EmailDb.pcNewInstance(EmailDb.java)
> 	at org.apache.openjpa.enhance.PCRegistry.newInstance(PCRegistry.java:117)
> 	at org.apache.openjpa.kernel.StateManagerImpl.initialize(StateManagerImpl.java:322)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:396)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:322)
> 	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)
> 	... 54 more

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message