Multivalue Mysql Inserts using HibernateTemplate

Posted by Langali on Stack Overflow See other posts from Stack Overflow or by Langali
Published on 2010-05-20T18:53:00Z Indexed on 2010/05/20 20:10 UTC
Read the original article Hit count: 227

Filed under:
|
|

I am using Spring HibernateTemplate and need to insert hundreds of records into a mysql database every second.

Not sure what is the most performant way of doing it, but I am trying to see how the multi value mysql inserts do using hibernate.

String query = "insert into user(age, name, birth_date) values(24, 'Joe', '2010-05-19 14:33:14'), (25, 'Joe1', '2010-05-19 14:33:14')"

getHibernateTemplate().execute(new HibernateCallback(){
 public Object doInHibernate(Session session) throws HibernateException, SQLException {
      return session.createSQLQuery(query).executeUpdate();
 }
});

But I get this error: 'could not execute native bulk manipulation query.' Please check your query .....

Any idea of I can use a multi value mysql insert using Hibernate? or is my query incorrect?

Any other ways that I can improve the performance? I did try the saveOrUpdateAll() method, and that wasn't good enough!

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about spring