New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InvalidDataAccessApiUsageException occurs when using @Procedure annotation [DATAJPA-1555] #1864
Comments
Jens Schauder commented You need to reference the The following method will call the stored procedure. @Procedure(procedureName="getAllCategoriesThroughStoredProcedure")
List<Category> getAllCategoriesThroughStoredProcedure(); |
Jens Schauder commented Can you please confirm that this works? |
Pavan Kumar Jadda commented Jens Schauder It did not work. I got the same error. One more thing, Spring Data JPA docs say, it has to be procedure name on Database, is this right syntax? /**
* The name of the procedure in the database, defaults to {@code ""}.
*/
String procedureName() default ""; |
Jens Schauder commented Sorry, it should be: @Procedure(name="getAllCategoriesThroughStoredProcedure")
List<Category> getAllCategoriesThroughStoredProcedure(); I rewrote the documentation about stored procedures just last week. You can use either In this case the missing information then becomes where to get the result from: a return value of the stored procedure or an At least that is my assumption so far. If this also turns out to be wrong I need some actual code reproducing the issue |
Pavan Kumar Jadda commented Jens Schauder I created https://github.com/pavankjadda/SpringDataDemo repository with code and instructions on how to run it. I also noted errors in Errors.md file for reference. Please have a look. By the way, I did look at your latest documentation, but the issue remains same |
Jens Schauder commented If you use the name used in |
Pavan Kumar Jadda commented Jens Schauder When you say lookup query, you mean this or something else @Query(value = "CALL get_all_categories;",nativeQuery = true)
List<Category> getAllCategoriesThroughStoredProcedure(); |
Pavan Kumar Jadda commented And for the being, I am using a new interface with Entity Manager execute my stored procedure CategoryRepositoryCustom.java public interface CategoryRepositoryCustom
{
List<Category> getAllCategoriesThroughStoredProcedure();
} CategoryRepositoryCustomImpl.java
@Repository
public class CategoryRepositoryCustomImpl implements CategoryRepositoryCustom
{
private final EntityManager entityManager;
private final ModelMapper modelMapper;
public CategoryRepositoryCustomImpl(EntityManager entityManager, ModelMapper modelMapper)
{
this.entityManager = entityManager;
this.modelMapper = modelMapper;
}
@Override
public List<Category> getAllCategoriesThroughStoredProcedure()
{
List<Category> categories=new ArrayList<>();
StoredProcedureQuery storedProcedureQuery=entityManager.createNamedStoredProcedureQuery("getAllCategoriesThroughStoredProcedure");
List<?> categoriesResult=storedProcedureQuery.getResultList();
categoriesResult.forEach(category -> categories.add(modelMapper.map(category, Category.class)));
return categories;
}
}
CategoryRepository.java public interface CategoryRepository extends JpaRepository<Category,Long>,CategoryRepositoryCustom
{
} |
Jens Schauder commented Pavan Kumar Jadda When I wrote "lookup" I meant Spring Data JPA finds the declaration of the named stored procedure and is able to determine the return type, so the original error does go away. |
Pavan Kumar Jadda opened DATAJPA-1555 and commented
I have an Entity class named 'Category' and trying use stored procedure based on the[ official docs |https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.stored-procedures].
Category.Java
CategoryRepository.Java
When I invoke getAllCategoriesThroughStoredProcedure() method I get an exception
I tried different syntaxes specified on official docs and everything throws the same error. I am using spring-boot-starter-data-jpa:2.1.5.RELEASE with Spring Boot 2.1.5
Affects: 2.1.8 (Lovelace SR8)
Reference URL: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.stored-procedures
Issue Links:
("duplicates")
The text was updated successfully, but these errors were encountered: