I have my entity class mapped like below:
@Entity
@Audited
@Table(name=\"messages_locale\")
public class Locale {
@Id
@GeneratedValue
@Getter @S
In PostgreSQL auto-increment is handled using the SERIAL
pseudo type. You use this type when you execute CREATE TABLE
.
Now to the point - this SERIAL
pseudo type creates a sequence.
Autoincrement in PostgreSQL
is handled using the created sequence. The default value of the id
column becomes - nextval('your_sequence_name')
.
In Hibernate for an User
entity:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "users_seq_gen")
@SequenceGenerator(name = "users_seq_gen", sequenceName = "users_id_seq")
public Long getId() {
return id;
}
Read here:
http://www.postgresql.org/docs/8.4/static/datatype-numeric.html#DATATYPE-SERIAL
http://www.neilconway.org/docs/sequences/