hibernate could not get next sequence value

后端 未结 11 1442
夕颜
夕颜 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: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;
    

提交回复
热议问题