kundera icon indicating copy to clipboard operation
kundera copied to clipboard

Cannot query by primary key column

Open dstrawson opened this issue 14 years ago • 5 comments

I want to use the Id column in a query, for example:

SELECT t FROM Thing t WHERE t.id = :idParam

(id is type Long, @Id in the entity definition class)

(and before you ask, I know that there is a em.find() method of course, the above is a simplified version of a more complex query)

Kundera throws the following exception:

java.lang.NullPointerException at com.impetus.kundera.metadata.model.EntityMetadata.getFieldType(EntityMetadata.java:847) at com.impetus.kundera.query.KunderaQuery.filterJPAParameterInfo(KunderaQuery.java:527) at com.impetus.kundera.query.KunderaQuery.onTypedParameter(KunderaQuery.java:489) at com.impetus.kundera.query.KunderaQuery.initFilter(KunderaQuery.java:456) at com.impetus.kundera.query.KunderaQuery.postParsingInit(KunderaQuery.java:331) at com.impetus.kundera.query.QueryResolver.getQueryImplementation(QueryResolver.java:75) at com.impetus.kundera.persistence.PersistenceDelegator.createQuery(PersistenceDelegator.java:550) at com.impetus.kundera.persistence.EntityManagerImpl.createQuery(EntityManagerImpl.java:337) at example.Test1.testQueryByPK(Test1.java:41) 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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41) at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173) 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:220) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 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)

dstrawson avatar Aug 02 '12 11:08 dstrawson

I've updated dstrawson/kunderatest with this as a test case and pushed back to github.

dstrawson avatar Aug 02 '12 11:08 dstrawson

Hi Daniel, As query support over Cassandra works over Secondary index, Secondary indexes can be done over columns only! Hence we have limited Kundera not to support. But team is working to convert such invocations in to "findById()" implicitly.

2.0.8 will have this change in. I would request you to let this open.

Thanks, Vivek

mevivs avatar Aug 02 '12 11:08 mevivs

I guess that this won't work as a range query, eg id>5 AND id<50 (with OPP this should work ok in CQL I think for example).

dstrawson avatar Aug 02 '12 13:08 dstrawson

Yes. With OPP it should work with Kundera as well.

mevivs avatar Aug 02 '12 14:08 mevivs

Working fine. Closing it

mevivs avatar Jan 23 '13 10:01 mevivs