Search code examples
javamysqlhibernatehqlnamed-query

Java Hibernate HQL can't specify target table


I was reading the Post from user @JB Nizet

Hibernate Exception on MySQL Cross Join Query

Later i have try my own code

I have a HQL like this.

update Student set newField='newField',anotherFieldsToBeUpdated where .... 
and id in
(select s.id from Student s where s.school=:school)
-->[Student->School]many to one relationship....

But still throws the infamous

Caused by: java.sql.SQLException: You can't specify target table 'Student' for update in FROM clause

I was wondering if still exists a solution without using another different select or use a temporal table.


Solution

  • When you access just one and the same table you can combine your limitation together:

    update Student set newField = :newField where ... and school = :school