3

Can I configure Hibernate not to do the select seq.nextval from dual as separate call before the actual insert ?

org.hibernate.jdbc.AbstractBatcher about to open PreparedStatement (open PreparedStatements: 0, globally: 0) org.hibernate.SQL select SEQUENCE_1.nextval from dual org.hibernate.id.SequenceGenerator auditor50 - Sequence identifier generated: 122797 org.hibernate.jdbc.AbstractBatcher auditor50 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1) <class..> <id column="ID" name="id" type="long"> <generator class="sequence"> <param name="sequence">SEQUENCE_1</param> </generator> </id> </class> 
3
  • How would it get the value to insert then? Commented Aug 9, 2011 at 10:05
  • insert into table (ID) VALUES (SEQUENCE.NEXTVAL); Commented Aug 9, 2011 at 10:07
  • I'm not sure if this would stop the current behavior, but what if in the database the default value was SEQUENCE.NEXTVAL? Commented Aug 9, 2011 at 10:12

1 Answer 1

1

I don't think this is possible. But I don't know what difference it would make. If you want to do this for performance reasons:

  1. Have you measured a significant difference between both approaches?
  2. Do you know that the sequence ID generator of Hibernate is in fact a hilo sequence ID generator, and that it only gets the next value every N inserts (N defaulting at 50, IIRC), making it certainly faster than you might think?
Sign up to request clarification or add additional context in comments.

3 Comments

1. I haven't really measured it, but I insert 200+ rows per transaction
2.For me it does every insert not every 50 inserts
2. My mistake. When configured via annotations, the sequence generator is in fact the seqhilo generator. With XML, you have to use class="seqhilo" rather than class="sequence"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.