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
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.
It worked for me after making the above change.
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;
I seem to recall having to use @GeneratedValue(strategy = GenerationType.IDENTITY)
to get Hibernate to use 'serial' columns on PostgreSQL.
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 ~
If using Postgres, create sequence manually with name 'hibernate_sequence'. It will work.
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;