When hibernate parses out this hql:
UPDATE VERSIONED Person SET groupsCount = followingGroup.size WHERE id = :id
it generates this sql:
UPDATE Person
SET version =version+1,
groupsCount=
(SELECT COUNT(followingg1_.followerId)
FROM GroupFollower followingg1_
WHERE Person.id=followingg1_.followerId
)-1
WHERE id IN
(SELECT groupfollo2_.followerId
FROM GroupFollower groupfollo2_
WHERE groupfollo2_.followingId=?
)
That query fails at the “-1” after the subquery for the count of the followingids. If i take out the “-1” it runs just fine, or if i move the “-1” to “SELECT COUNT(followingg1_.followerId) – 1” it also works.
I don’t see how to work around this, short of using db specific sql, is this a bug with 11g?
Ok, i found the problem, I was wrong, that statement deals with a “Person” object, which is more complicated that I first realized, although it was at that line that the test was failing, it was actually hql in the class it was testing that produced the sql that was the problem.
So that answers the first part, the second part of the answer is that its a known bug apparently in oracle 10g that you can’t do arithmetic operations after the subquery in an update statement (duh!) so changing the above to
works just fine. phew-