0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
chiperortiz
  • 4,751
  • 9
  • 45
  • 79
  • Can you tell in words what is your query purpose? And what is the relationship between Student and School? – MaxZoom Feb 24 '15 at 16:05

1 Answers1

1

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

update Student set newField = :newField where ... and school = :school
MaxZoom
  • 7,619
  • 5
  • 28
  • 44
  • Glad I could help. In case you need more info, refer to the [HQL](http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html) specification. – MaxZoom Feb 24 '15 at 17:40