2

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?

Aniket V
  • 3,183
  • 2
  • 15
  • 27
kosa
  • 65,990
  • 13
  • 130
  • 167
  • What version of Hibernate are you using? Specifically, is 'prefer_sequence_per_entity' supported in the version you are using? – Steve Ebersole Sep 21 '13 at 18:29
  • @SteveEbersole: I am using hibernate 4.0. I couldn't find "prefer_sequence_per_entity" in hibernate documentation. Is this available? If so, can you share link to documentation? – kosa Sep 23 '13 at 03:21

1 Answers1

4

'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

Steve Ebersole
  • 9,339
  • 2
  • 48
  • 46