Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could hibernate be causing this 'fetch out of sequence' error?

I am attempting to execute this query (in an Oracle DB) with Hibernate/Spring JPA:

@Query( value = "DELETE from MY_TABLE where ID = :ID", nativeQuery = true)
    void delete(Long ID);

There is a BEFORE DELETE trigger on the table that is making up for poor table design that I cannot change, it runs around deleting rows from dependent tables so that the base DELETE doesn't cause any foreign key errors. I am fairly sure this shouldn't be an issue, but if it is let me know.

Now then, on execution this query causes a ORA-01002: fetch out of sequence error which, according to google, is caused when a fetch has been attempted from a cursor which is no longer valid. (To be completely clear, I have not initiated any cursors with my query or my trigger)

BUT, the row and all its dependants are actually being deleted successfully. Because of this I am not sure what is causing the error and would like yalls' help

like image 280
Ridiculon Avatar asked Jan 09 '20 17:01

Ridiculon


Video Answer


1 Answers

The method should be :

@Modifying
@Query( value = "DELETE from MY_TABLE where ID = :ID", nativeQuery = true)
    void delete(@Param("ID") Long ID);

Try this and check if the issue still exists.

like image 57
Nitika Bansal Avatar answered Nov 09 '22 23:11

Nitika Bansal