When I gave my talk on Monday I’d sort of hurried over the new bulk queries in Hibernate, largely because I didn’t have much luck finding doco on them.
Now I know how they work.
You can use the bulk update and delete queries very easily. Simply create a new Query object, using the right HSQL. As you’d expect, it looks a lot like the equivalent SQL. Having created it, you call
executeUpdate on it to have it processed.
Session session = ...; Query deleteQuery = session.createQuery("delete from Foo foo where foo.bar = 'baz'"); deleteQuery.executeUpdate();
I don’t know the update syntax, but I’d be suprised if it wasn’t like this:
Query updateQuery = session.createQuery("update Foo foo set foo.bar = 'baz' where foo.qux = 'quux'"); updateQuery.executeUpdate();