Matias Paterlini

Helping to make the world more social and connected

Hibernate error: "could not execute native bulk manipulation query"

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

Comments

funny wallpaper » Hibernate error: “could not execute native bulk manipulation query” said:

Pingback from  funny wallpaper » Hibernate error: “could not execute native bulk manipulation query”

# September 3, 2008 6:09 PM

Gauthier Segay said:

Just as a hint, I would use

session.CreateSqlQuery("DELETE VotableNode vn WHERE vn.votingSetBucketId = :bucketId").SetParameter("bucketId", buckedId).ExecuteUpdate();

that should work

# September 4, 2008 3:18 AM

Pascal Forget said:

Actually, I am able to do a bulk delete using Hibernate on a PostgreSQL 8.3, but it doesn't work on PostgreSQL 8.0.

# September 5, 2008 8:00 AM

Shahriar said:

Thanks man you saved me from alot of trouble on searching the bloody exception error.

# November 21, 2008 4:50 AM

Diego Arvin said:

Thank you...

# May 27, 2009 10:48 AM

jifei_huang said:

Thanks for your help.

# August 7, 2009 5:22 AM

Pieter said:

Hi Matias,

This is because your SQL statements points to the name of your hibernate bean.  You need to use the name of you database tables.

VotableNode is a hibernate bean name, and not a tablename.

Good luck,

Pieter Pareit

http://www.art-gallery.be

# September 3, 2009 8:30 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)