Problem still remains, see below.
The first query I suggested:
Code:
update product set is_visible = is_visible_temp;
works fine in mysql. However, the query with the subselect does not work in mysql 5. From their Update documentation:
Quote:
Currently, you cannot update a table and select from the same table in a subquery.
http://dev.mysql.com/doc/refman/5.0/en/update.htmlSo I hadn't tested the subselect query in mysql 5, just assuming that it would work fine. I guess the newness of subselects in mysql 5 is showing.
Thanks for the suggestion to show the SQL. I should have used that before! I am using the Hibernate Tools in eclipse and was able to see that my query first was incorrect:
Code:
update Product p set p.isVisible where p.id in (select p.id from Product p where p.isVisibleTemp = true)
should have a value to set isVisible to like this:
Code:
update Product p set p.isVisible = true where p.id in (select p.id from Product p where p.isVisibleTemp = true)
Silly me. When I fixed that, the Hibernate Dynamic Query Translator gave me the SQL query that would be run. I tried to run that in mysql 5 and got the error I mentioned above. It looks like I'll have to try to get the other update to work.
So I tried to get this query to run in the Hibernate Console:
Code:
update Product p set p.isVisible = p.isVisibleTemp
First, the Hibernate Dynamic Query Translator translated the HQL into the following SQL:
Code:
update product set is_visible=is_visible_temp
When I run the HQL in the Hibernate Console, it does not work, though it returns no error. However when I run the translated SQL statement that it gives me on the mysql commandline, it works fine.
I guess my problem remains but for a different reason. Any idea as to why Hibernate gets the right SQL but that SQL doesn't update the records correctly?