Rodriguez
Rodriguez

Reputation: 452

configure id sequence hibernate generator

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>

Upvotes: 3

Views: 1710

Answers (1)

JB Nizet
JB Nizet

Reputation: 691625

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?

Upvotes: 1

Related Questions