Espanol  |  English      

Archive

Posts Tagged ‘BULK’

Hibernate error: “could not execute native bulk manipulation query”

September 1st, 2008

I was getting this error:

exception: org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query

After looking in more than 25 google results I couldn’t find any clue about what could be happening. But somehow I got illuminated and found what was happening. That’s why I’m writing this post.

This was my code before I saw the problem:

  1. String del = “DELETE VotableNode vn WHERE vn.votingSetBucketId = “ + Integer.toString(bucketId);
  2. session.createSQLQuery(del).executeUpdate();

Let Me tell you something about this error. I’m not a hibernate crack, but as you can see it’s saying that you can’t create a bulk delete on a sql query by using hibernate.

The error in this code is that I was executing a HQL script using createSQLQuery method which is completely wrong, I should use createQuery.

  1. String del = “DELETE VotableNode vn WHERE vn.votingSetBucketId = “ + Integer.toString(bucketId);
  2. session.createQuery(del).executeUpdate();

So there’s nothing much to say, If you want to make a bulk task like an update of multiple records or a deletion of multiple rows using a simple query, you MUST use a HQL query.

Hope that helps a little!

Matias Paterlini

paterlinimatias Development, GWT EXT, Java , , , , , ,