How can i call stored procedure using spring with jpa

前端 未结 3 528
温柔的废话
温柔的废话 2020-12-17 04:54

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

3条回答
  •  抹茶落季
    2020-12-17 05: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.

提交回复
热议问题