How the new Hibernate bulk queries work

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 = 'baz'");

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 = 'baz' where foo.qux = 'quux'");

Author: Robert Watkins

My name is Robert Watkins. I am a software developer and have been for over 20 years now. I currently work for people, but my opinions here are in no way endorsed by them (which is cool; their opinions aren’t endorsed by me either). My main professional interests are in Java development, using Agile methods, with a historical focus on building web based applications. I’m also a Mac-fan and love my iPhone, which I’m currently learning how to code for. I live and work in Brisbane, Australia, but I grew up in the Northern Territory, and still find Brisbane too cold (after 22 years here). I’m married, with two children and one cat. My politics are socialist in tendency, my religious affiliation is atheist (aka “none of the above”), my attitude is condescending and my moral standing is lying down.

3 thoughts on “How the new Hibernate bulk queries work”

  1. Hi everybody,I am writing a hibernate query that multiply two attributes and takes it sum, but when I use * operator,it gives error “* only allowed inside aggregate function in SELECT ” . HQL query is :

    count(postab.checknum) ,
    com.infonox.hibernate.Location as loc,
    com.infonox.hibernate.Postables as postab
    where loc.restaurantid = postab.restaurantid


    Line which is creating problem is

    Is there any other way to take product of two attributs? your help will be greatly appreciated as it is really stumbling block in my project. Thanks in advance

  2. For starters, drop the select. With the select, you’ve written SQL, not HQL.

    Other than that: I’m not sure. It sort of looks okay, but I’m not an expert. I strongly suggest you take questions like this to the Hibernate user forums at

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: