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();
It’s documented in the EJB3 specification drafts, as mentioned in the Hibernate API docs.
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 :
****************************************************************
Select
sum(postab.subtotal),
sum(postab.tax),
sum(postab.total),
count(postab.checknum) ,
Sum((postab.subtotal)*(loc.royalty)/100)
From
com.infonox.hibernate.Location as loc,
com.infonox.hibernate.Postables as postab
where loc.restaurantid = postab.restaurantid
****************************************************************
Line which is creating problem is
Sum((postab.subtotal)*(loc.royalty)/100)
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
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 hibernate.org.