I would like to ask if someone considered the possibility to add some "bulk update" feature in hibernate. I mean if I would like to assign a lot of instances of some class the same value of one property I have to load them all from DB, change them one-by-one a also save them one-by-one. I think there should be more efficient way, because this could be done by one simple SQL statement. Something like an UpdateProperty method of criteria interface, so I could create the criteria object and then just change some property to specified value in one method call, which would result into one UPDATE command in SQL. Of course it would be nice to have the ability to use expresions and not just constant values and be able to change more properties in one UPDATE command, but I think that even the basic feature would be very useful. I know that I can accomplish this task by writing a direct SQL command by myself, by it would be really nice to be able to do such thing through hibernate, especialy if you have already the criteria object for this update prepared from some other operation. It would be very similar to the unofficial count() method of criteria interface (you can vote for this count() method on JIRA), just instead of SELECT COUNT(*) FROM table WHERE ... it would do UPDATE table SET prop = value WHERE ...
|