Batch insert mode with hibernate and oracle: seems to be dropping back to slow mode silently

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-07-22T04:21:12Z Indexed on 2012/07/03 15:16 UTC
Read the original article Hit count: 180

Filed under:
|
|

I'm trying to get a batch insert working with Hibernate into Oracle, according to what i've read here: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/batch.html , but with my benchmarking it doesn't seem any faster than before.

Can anyone suggest a way to prove whether hibernate is using batch mode or not? I hear that there are numerous reasons why it may silently drop into normal mode (eg associations and generated ids) so is there some way to find out why it has gone non-batch?

My hibernate.cfg.xml contains this line which i believe is all i need to enable batch mode:

<property name="jdbc.batch_size">50</property>

My insert code looks like this:

List<LogEntry> entries = ..a list of 100 LogEntry data classes...
Session sess = sessionFactory.getCurrentSession();
for(LogEntry e : entries) {
  sess.save(e);
}
sess.flush();
sess.clear();

My 'logentry' class has no associations, the only interesting field is the id:

@Entity
@Table(name="log_entries")
public class LogEntry {
  @Id @GeneratedValue
  public Long id;
  ..other fields - strings and ints...

However, since it is oracle, i believe the @GeneratedValue will use the sequence generator. And i believe that only the 'identity' generator will stop bulk inserts.

So if anyone can explain why it isn't running in batch mode, or how i can find out for sure if it is or isn't in batch mode, or find out why hibernate is silently dropping back to slow mode, i'd be most grateful.

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about Oracle