Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HIbernate 5: generator class="sequence" not working

I have following mapping:

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

Everything went fine when I worked with it in Hibernate 4.2. Now I am migrating to Hibernate 5 and facing following issue:

2015-10-06 19:49:50 DEBUG SQL:92 - select nextval ('hibernate_sequence')
2015-10-06 19:49:50 DEBUG SqlExceptionHelper:122 - could not extract ResultSet [n/a]
org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist

How to resolve this issue?

P.S. Hibernate 5.0.2.Final.

like image 824
Green Root Avatar asked Oct 06 '15 20:10

Green Root


2 Answers

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>
    
like image 186
Mark Ola Avatar answered Oct 18 '22 19:10

Mark Ola


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

That worked for me.

like image 3
Pavan Ghantasala Avatar answered Oct 18 '22 18:10

Pavan Ghantasala