I'm trying to call a stored procedure in MySQL call: "searchContext".
I have tried the solution : here and here
But how can I get the EntityManager reference? If I'm using JPA Repositories like this:
public interface ActiveContextRepository extends JpaRepository<ActiveContext, Long> {
ActiveContext findByIdUser(Integer idUser);
}
I got null pointer when I use EntityManager like this:
public class ContextService {
@PersistenceContext
protected EntityManager entityManager;
public EntityManager getEntityManager() {
return entityManager;
}
public Integer getContext(Integer idUser, String date, Double longitude, Double latitude){
StoredProcedureQuery storedProcedure = entityManager.createStoredProcedureQuery("searchContext");
}
Or like this:
public class ContextService {
@Autowired EntityManager entityManager;
public Integer getContext(Integer idUser, String date, Double longitude, Double latitude){
StoredProcedureQuery storedProcedure = entityManager.createStoredProcedureQuery("searchContext");
}
I also haved tried this solution:here But precompiler gives me an error on the Jpa repository:
"Invalid derived query!No property search found for a type ActiveContext"
Thank you very much!