Hibernate / MySQL Bulk insert problem

Posted by Marty Pitt on Stack Overflow See other posts from Stack Overflow or by Marty Pitt
Published on 2010-02-20T18:21:38Z Indexed on 2010/05/02 16:57 UTC
Read the original article Hit count: 211

Filed under:
|
|
|

I'm having trouble getting Hibernate to perform a bulk insert on MySQL.

I'm using Hibernate 3.3 and MySQL 5.1

At a high level, this is what's happening:

@Transactional
public Set<Long> doUpdate(Project project, IRepository externalSource) {
    List<IEntity> entities = externalSource.loadEntites();
    buildEntities(entities, project);
    persistEntities(project);
}
public void persistEntities(Project project) {
     projectDAO.update(project);
}

This results in n log entries (1 for every row) as follows:

Hibernate: insert into ProjectEntity (name, parent_id, path, project_id, state, type) values (?, ?, ?, ?, ?, ?)

I'd like to see this get batched, so the update is more performant. It's possible that this routine could result in tens-of-thousands of rows generated, and a db trip per row is a killer.

Why isn't this getting batched? (It's my understanding that batch inserts are supposed to be default where appropriate by hibernate).

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate