I found similar questions about this error but I can’t make it work
I’m working on a java 8, spring 2.6.4 and a MySQL database
I’m trying to do a DELETE native query using JPA and I’m getting this error:
org.springframework.orm.jpa.JpaSystemException: could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet
this is my query:
@Query(value = "DELETE FROM reservation a WHERE a.slotid =:slotid", nativeQuery = true)
void deleteWhereSlotid(Integer slotid);
and this is the service:
repo.deleteWhereSlotid(reservationSlot.getId());
I’ve also tried:
@Query(value = "DELETE FROM reservation a WHERE a.slotid =:slotid", nativeQuery = true)
Object deleteWhereSlotid(Integer slotid);
//service
Object object= userCourseResRepo.deleteWhereSlotid(reservationSlot.getId());
but it failed
Usually I delete rows with deleteById(id)
which comes with spring
The query works though, I tried it on phpMyadmin console and it worked
Someone know what I can try?
4
Answers
If you are using it that way, I believe the query should be:
I am not particularly sure about the code, however, with Mysql, the case seems to be so when giving an alias to the table.
I know is not the best solution, but you can try to use a query SELECT to find your reservation object and then do this
repo.deleteById(reservation.getId())
This should allow you to go ahead while you find a better way to do it
The way you have it set up, Spring Data assume you want to perform a query (typically a
SELECT
). ForDELETE
and similar statements that don’t return aResultSet
you need to provide an additional@Modifying
annotation.You need to add @Param
As mentioned above, we use the
@Param
annotation in the method declaration to match parameters defined by name in JPQL/Native query with parameters from the method declaration.