1

I have an application that does quite a bit of batch inserts. I'd like to optimize the application to do these as fast as possible.

I see several Hibernate Settings that I think have to do with batch inserts:

  • hibernate.jdbc.batch_size
  • hibernate.jdbc.batch_versioned_data
  • hibernate.jdbc.use_get_generated_keys

I'm not sure if I need to set these properties. If I do need to set them, I'm not sure what the correct values are.

Is it safe to set hibernate.jdbc.batch_versioned_data and hibernate.jdbc.use_get_generated_keys to true for my version of Oracle?

How do I choose a batch size?

I am using the following versions of these libraries:

  • Hibernate: 3.2.3 GA
  • Oracle Database: 11G
  • Oracle Database Driver: 11.2.0.3.0
  • c3p0: 0.9.1.2
Adam
  • 43,763
  • 16
  • 104
  • 144

1 Answers1

2

hibernate.jdbc.batch_size This should be set to a reasonable value that suits your requirements (recommended is between 5 and 30).

hibernate.jdbc.batch_versioned_data This is not safe for your database and JDBC driver version (see this question for more details). Do not turn this on. Otherwise, the optimistic locking mechanism will be silently broken for versioned entities.

hibernate.jdbc.use_get_generated_keys This is used by some Hibernate id generators that retrieve natively generated keys after insert (when auto-increment columns and similar are used for primary key generation). You have to enable it if you use such id generators regardless of whether batching is used or not.

Also, make sure to enable hibernate.order_inserts. More details on this flag and Hibernate batching in general can be found here.

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110
  • 1
    Thanks! I use Oracle sequences for most IDs, e.g. seq_mytable_id Do those need hibernate.jdbc.use_get_generated_keys ? – Adam Dec 22 '15 at 20:54
  • Why do I need hibernate.order_inserts? – Adam Dec 22 '15 at 20:55
  • _"Do those need `hibernate.jdbc.use_get_generated_keys`?"_ No, they don't, because ids are fetched from the sequence prior to issuing `insert` statements._"Why do I need `hibernate.order_inserts`?"_ Regarding this and similar flags, please read the blog I linked to in the answer. – Dragan Bozanovic Dec 24 '15 at 11:17