Use Oracle sequence ID in Hibernate

Today I had tried a few times with hibernate using oracle sequence ID. The params of the generator was not very clear from documentations. But after a few permutation, it turns out this works nicely.

<id name=”file_id” type=”long” column=”file_id”>
<generator class=”sequence” />
<param name=”sequence”>file_seq_id</param>
</generator>
</id>

This requires pre-generation of file_seq_id sequence in oracle database. It is also good for cluster
use. Increment type is not.

T

Advertisements

One thought on “Use Oracle sequence ID in Hibernate

  1. This is related to the sequence. Oracle by default doesn’t ensure the sequence is continuous. You have to make it nocache if you want that. Like this. So oracle system will not “lose” any cached sequence number, which contributes the gaps. Obviously, it might have some performance impact.

    DROP SEQUENCE FILE_SEQ_ID;

    CREATE SEQUENCE FILE_SEQ_ID
    MINVALUE 1
    MAXVALUE 999999999999999999999999999
    START WITH 100
    INCREMENT BY 1
    NOCACHE;

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s