Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Hibernate 5 sequence generator use the default hibernate.seq instead of my sequence?

Aftre migrate my application from hibernate 4 to hibernate 5 .my sequence dose not work and hibernate use our default sequence instead of my sequence .my mapping config in hbm like this my database is oracle .

<id name="id"  column="Id" type="java.lang.Long">
    <generator class="sequence" >
            <param name="sequence">SEQ_APP_Login_Log</param>   
    </generator>
</id>

after google some people say change class to org.hibernate.id.enhanced.SequenceStyleGenerator but dose not work again.

like image 913
ali akbar azizkhani Avatar asked Feb 12 '17 18:02

ali akbar azizkhani


People also ask

How does Hibernate sequence generator work?

SEQUENCE Generation. To use a sequence-based id, Hibernate provides the SequenceStyleGenerator class. This generator uses sequences if our database supports them. It switches to table generation if they aren't supported.

How do you define a sequence generated primary key in Hibernate?

First of all, you have to annotate the primary key attribute with the @GeneratedValue annotation and set GenerationType. SEQUENCE as the strategy. This tells Hibernate to use a database sequence to generate the primary key value. If you don't provide any additional information, Hibernate will use its default sequence.

What is allocationSize in sequence generator?

allocationSize. (Optional) The amount to increment by when allocating sequence numbers from the sequence.

What is @SequenceGenerator in Hibernate?

With SequenceGenerator Hibernate will query the database only when amount of IDs specified by allocationsize runs out. If you set up allocationSize = 1 then it's the reason why Hibernate query the DB for each insert. Change this value, and you are done.


1 Answers

It's simple. The sequence attribute has changed to sequence_name:

<id name="id" column="Id" type="java.lang.Long">
    <generator class="sequence" >
            <param name="sequence_name">SEQ_APP_Login_Log</param>   
    </generator>
</id>
like image 56
Vlad Mihalcea Avatar answered Oct 09 '22 00:10

Vlad Mihalcea