Pergunta

I am working on a requirement where we need to use sequence per entity.

Right now I have created a table hibernate_sequence with columns and values as below:

next_value | sequence_name
-----------|--------------
 100000045 | 
 100050000 | ACCOUNT_SEQ

Following is my hbm.xml file for entity ACCOUNT:

<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator"> 
            <param name="prefer_sequence_per_entity">true</param> 
            <param name="optimizer">none</param>
            <param name="increment_size">1</param> 
</generator>

But somehow my inserts using global sequence id instead of using sequence defined for ACCOUNT. Can somebody please point out what I am doing wrong here?

I did refer Steve answer for this question, but hibernate documentation is not clear on how to use this feature. Should we have a separate table for each entity (or) same table with different rows per each entity with some well-defined syntax?

Foi útil?

Solução

'prefer_sequence_per_entity' was not added until 4.1.3 (see https://hibernate.atlassian.net/browse/HHH-6790). Above you clarified that you are using 4.0. You'll need to upgrade to use that, or copy over the 4.1.3 version of SequenceStyleGenerator

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top