hibernate could not get next sequence value

后端 未结 11 1393
夕颜
夕颜 2020-11-29 23:32

i have gwt application connect to postgres DB at the backend, and a java class \'Judgement\' mapping the table \'judgements\' in DB, when i tried to persistent a judgement i

相关标签:
11条回答
  • 2020-11-30 00:07

    The Database that we are using should be mentioned under search_path in Postgres SQL Configuration file. This can be done by editing Postgressql configuration file by setting search_path along with database name for example: TESTDB.

    1. Find postgressql.conf file under data folder of Postgres SQL datbase.
    2. Set search_path = "$user", public, TESTDB;
    3. Restart the Postgres SQL service to affect the change.

    It worked for me after making the above change.

    0 讨论(0)
  • 2020-11-30 00:09

    You need to set your @GeneratedId column with strategy GenerationType.IDENTITY instead of GenerationType.AUTO

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "JUD_ID")
    private Long _judId;
    
    0 讨论(0)
  • 2020-11-30 00:15

    I seem to recall having to use @GeneratedValue(strategy = GenerationType.IDENTITY) to get Hibernate to use 'serial' columns on PostgreSQL.

    0 讨论(0)
  • 2020-11-30 00:20

    I got same error before, type this query in your database CREATE SEQUENCE hibernate_sequence START WITH 1 INCREMENT BY 1 NOCYCLE;

    that's work for me, good luck ~

    0 讨论(0)
  • 2020-11-30 00:23

    If using Postgres, create sequence manually with name 'hibernate_sequence'. It will work.

    0 讨论(0)
  • 2020-11-30 00:28

    Using the GeneratedValue and GenericGenerator with the native strategy:

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_native")
    @GenericGenerator(name = "id_native", strategy = "native")
    @Column(name = "id", updatable = false, nullable = false)
    private Long id;
    

    I had to create a sequence call hibernate_sequence as Hibernate looks up for such a sequence by default:

    create sequence hibernate_sequence start with 1 increment by 50;
    grant usage, select on all sequences in schema public to my_user_name;
    
    0 讨论(0)
提交回复
热议问题