Am new to SPRING with JPA techniques.
am trying to call the stored procedure which is written in mysql 5. when i am trying to get the data using stored procedure cal
JPA 2.1 introduced support for stored procedures. You might want to give it a try instead of a native queries.
http://docs.oracle.com/javaee/7/api/javax/persistence/EntityManager.html#createStoredProcedureQuery%28java.lang.String%29
Use EntityManager.createNativeQuery() instead. I don't think it's possible to call a stored procedure through a JPA query.
public List doInJpa(EntityManager em) throws PersistenceException {
javax.persistence.Query query=em.createNativeQuery("call st_proc_getusers()");
return query.getResultList();
}
You could also use @NamedNativeQuery.
Calling a stored procedure means executing some SQL statement. You can't do that with with a JPQL query (what you get in your code when you do em.createQuery(...)
). You must create a native query that allows you to send native SQL to the database, execute it and get the results:
String query = "call st_proc_getusers(?)";
NativeQuery nq = em.createNativeQuery(query);
//the following line is necessary only if your stored procedure accepts a parameter:
nq.setParameter(1, "paramValue");
List<?> results = em.createNativeQuery(query).getResultList();