Hibernate sequence on oracle, @GeneratedValue(strategy = GenerationType.AUTO)

These Annotations are no creating two sequences, only one. Is this correct/expected?

That’s the expected behavior. When using @GeneratedValue(strategy = GenerationType.AUTO), the JPA provider will pick an appropriate strategy for the particular database. In the case of Oracle, this will be SEQUENCE and, since you did not specify anything, Hibernate will use a single global sequence called hibernate_sequence.

Is this correct? Well, I don’t know, it depends on your needs. Just in case, the default maximum value for an Oracle sequence is 1E+27, or 1,000,000,000,000,000,000,000,000,000. That’s enough for many.

Now, it is possible to use GenerationType.AUTO and still control the name of the sequence when the database uses sequences:

@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="my_entity_seq_gen")
@SequenceGenerator(name="my_entity_seq_gen", sequenceName="MY_ENTITY_SEQ")
private Long id;

Leave a Comment