I was trying to SELECT
from createQuery
like this:
Query query3 = em.createQuery("SELECT t FROM Tag t WHERE t.name IN (:tag1, :tag2)");
query3.setParameter("tag1", "tag1");
query3.setParameter("tag2", "tag2");
Set<Tag> tags = new HashSet<Tag>(query3.getResultList());
This code works fine, however I got this warning:
Type safety: The expression of type List needs unchecked conversion to conform to List
So, according to this answer , I replce Query
with TypedQuery
like this:
TypedQuery<Tag> query2 = em.createQuery("SELECT t FROM Tag t WHERE t.name IN (:tag1, :tag2)", Tag.class);
query2.setParameter("tag1", "tag1");
query2.setParameter("tag2", "tag2");
Set<Tag> tags = new HashSet<Tag>(query2.getResultList());
The warning is disappeared, but when I run it, it produces a run-time error like this:
java.lang.AbstractMethodError: org.apache.openejb.persistence.JtaEntityManager.createQuery(Ljava/lang/String;Ljava/lang/Class;)Ljavax/persistence/TypedQuery;
at ut.ConfTest.testCreatePost(ConfTest.java:269)
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:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
I can't figure out what's wrong with my code. Did I mess up something with TypedQuery?
This exception commonly occurs when we use an old version of an interface
implementation which is missing a new interface
method. You can check the older version method you are using in your code and change this method with latest version.
it might be cause of due to some version
compatibility.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.