-2

Anyone came across this error? I used JPA to call a stored procedure query.

java.lang.NoSuchMethodError: javax.persistence.EntityManager.createStoredProcedureQuery(Ljava/lang/String;)Ljavax/persistence/StoredProcedureQuery;
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
  • Can you add more detais? (es: code) – PaolaG Jun 12 '15 at 13:49
  • 1
    `NoSuchMethodError` means that you are most likely compiling your code with one version of some library, and you are running your code with a different, incompatible version of that library. For example, you compile your code with a newer version of the JPA API than what your runtime environment provides. Use the same versions for compiling and running. – Jesper Jun 12 '15 at 13:50

2 Answers2

0

The method EntityManager.createStoredProcedureQuery(String procedureName) is new in JPA version 2.1.

You are compiling your code against JPA 2.1, but you are running it in an environment that supports an older version of JPA.

Solution: Find out what version of JPA your environment supports, and use that when you compile your code; or update the environment that you use to run your application to a version that supports JPA 2.1.

Jesper
  • 202,709
  • 46
  • 318
  • 350
  • can i use javax.persistence library on java 6? – Sandun Chathuranga Feb 02 '17 at 09:19
  • @SandunChathuranga Yes, you can use JPA on Java 6. You'll need an implementation of JPA that is compatible with Java 6, for example [Hibernate version 5.1 or older](http://hibernate.org/orm/documentation/getting-started/). – Jesper Feb 02 '17 at 15:55
  • yeah. im using hibernate 3 and hibernate JPA 2.1. but i cannot use createStoredProcedureQuery method in EntityManager class. – Sandun Chathuranga Feb 03 '17 at 04:15
  • @SandunChathuranga Hibernate 3 does not support JPA version 2.1; you'll need Hibernate version 4.3 or newer. See: [Which version of Hibernate supports JPA 2.1?](http://stackoverflow.com/questions/14558931/which-version-of-hibernate-support-jpa-2-1) – Jesper Feb 03 '17 at 08:02
0

This happens if you are using an interface that contains the method (createStoredProcedureQuery), but the runtime instance of the object doesn't have the method, for example because it was compiled with the previous version of the interface.

In this specific case you seem to be using a JPA implementation that doesn't support methods added in Java EE 7. You might want to check if there is a newer version of the library available.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197