kgignatyev wrote:
So you I guess you have to use SQL
Well, not quite. As I mentioned earlier, I can write some HQL that works that is more like the SQL:
Code:
delete from Address where owner in (from Owner o where o.lastName = ?)
So I don't have to resort to direct SQL.
Really, what I had in mind here, though, was to feel out whether the other syntax might be a reasonable feature. To wit:
I think we've established that using property paths in the where-clause of an HQL bulk delete doesn't work. The solution in my case was that it had to be written as an IN constraint using a subselect.
Thinking through things, I understand now why HQL does not support paths in the where-clause, but because I'm used to using paths in select statements, it never occurred to me that they wouldn't work in a bulk delete. I believe this is what the documentation means when it refers to "implicit joins":
Quote:
No joins (either implicit or explicit) can be specified in a bulk HQL query. Sub-queries may be used in the where-clause.
However, the documentation did not really make this obvious to me, and I didn't really realize the implications of the quoted text until after I ran into the problem. If nothing else comes of this thread, I would ask that whoever maintains the reference consider adding a bit more text to explicitly discuss property paths -- perhaps with an example or two.
The other goal I had was to feel out whether this could ever be a hibernate feature. I understand that it could be rather complex, as hibernate would have to know how to convert something like this:
Code:
delete from Address where owner.lastName = ?
Into SQL that uses a subquery like this:
Code:
delete from Address a where a.owner_id in (select p.id from Person p where p.lastName = ?)
You don't have to be a ORM expert to see that something like this might grow fairly complex fairly quickly. But if it could be done, I feel it would be a very useful addition to the HQL language. After all, my initial intuition was to use property paths to achieve the desired results. You can really see where this would be powerful in more complex situations. Consider:
Code:
delete from Car where brakeSystem.isABS = true and suspension.tires.maxInflationPSI = 45
The SQL for this would not be simple, but the HQL cetainly is!
That said, though, I'm not in the habit of just tossing feature requests into a project's tracking software before I know whether the change is feasible (or in this case, even possible). In fact, I usually prefer to let someone who is more involved in the project make the decision of whether it should be considered for a new feature altogether
thoughts?