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.
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.
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.
allocationSize. (Optional) The amount to increment by when allocating sequence numbers from the sequence.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With