Home > Blockchain >  GenericJDBCException: could not extract ResultSet
GenericJDBCException: could not extract ResultSet

Time:07-13

I found similar questions about this error but i can't make it work

I'm woking on a java 8, spring 2.6.4 and a mySQL database

Im trying to do a DELETE native query using JPA and im 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) wich comes with spring

The query works tho, i tried it on phpMyadmin console and it worked

Someone know what i can try?

CodePudding user response:

If you are using it that way, I believe the query should be:

DELETE a FROM reservation a WHERE a.slotid =:slotid

I am not particularly sure about the code, however, with Mysql, the case seems to be so when giving an alias to the table.

CodePudding user response:

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

CodePudding user response:

The way you have it set up, Spring Data assume you want to perform a query (typically a SELECT). For DELETE and similar statements that don't return a ResultSet you need to provide an additional @Modifying annotation.

@Modifying
@Query(value = "DELETE FROM reservation a WHERE a.slotid =:slotid", nativeQuery = true)
void deleteWhereSlotid(Integer slotid);
  • Related