HIbernate 5: generator class=“sequence” not working

前端 未结 3 550
遥遥无期
遥遥无期 2021-02-09 04:22

I have following mapping:

    
        
            

        
相关标签:
3条回答
  • 2021-02-09 04:40

    I also encountered this problem when migrating from Hibernate 4.3.10 to Hibernate 5.0.4. Like maksim2020, I replaced instances of <generator class="sequence"> with <generator class="identity">. However, to preserve the id sequence for the affected tables I also had to write a sql migration script which set the default value for the column to be the next value of the existing sequence. In PostgreSQL this is done as follows:

    ALTER TABLE ONLY affected_table ALTER COLUMN affected_id SET DEFAULT nextval('original_sequence'::regclass);
    
    0 讨论(0)
  • 2021-02-09 04:42

    Use "sequence_name" instead of "sequence" in <param name="sequence">.

    That worked for me.

    0 讨论(0)
  • 2021-02-09 04:52

    You have two options:

    1. You set the hibernate.id.new_generator_mappings configuration property to false and switch back to the old identifier generators
    2. You change the mapping as follows, from this:

      <generator class="sequence">
          <param name="sequence">MY_SEQUENCE</param>
      </generator>
      

      to:

      <generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
          <param name="optimizer">none</param>
          <param name="increment_size">1</param>
          <param name="sequence_name">MY_SEQUENCE</param>
      </generator>
      
    0 讨论(0)
提交回复
热议问题