0

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?

Community
  • 1
  • 1
Nier
  • 638
  • 7
  • 15
  • so something (OpenEJB) is using a different version of JPA than what you expect. Look at the respective versions of OpenEJB, your JPA provider, the JPA API jar, etc – Neil Stockton Mar 28 '16 at 08:20
  • @NeilStockton I'm using **openejb-3.1.4** and **EclipseLink 2.6**, which seems to use **javax.persistence_2.1.1** according to the jar file name. I thought TypedQuery is usable in JPA 2.x. – Nier Mar 28 '16 at 08:33
  • eclipselink uses JPA 2.1, yes. Does OpenEJB? because it is OpenEJB that the exception complains about not implementing a JPA 2 method, and my strong suggestion based on that error message is NO it does not, it is built against JPA 1! – Neil Stockton Mar 28 '16 at 08:46
  • @NeilStockton Ok I see, according to [Apache OpenEJB 3.1.4](http://tomee.apache.org/download/apache-openejb-3.1.4.html), it seems **OpenEJB 3.1.4** only supports **OpenJPA 1.2.1**. Looks like I uses a old version of OpenEJB which is not support JPA 2. Thanks. – Nier Mar 28 '16 at 09:01

1 Answers1

0

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.

Sai prateek
  • 11,842
  • 9
  • 51
  • 66