I am getting a problem using hibernate with postgresql
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@Column(name = "id")
private Long id;
the problem is the id is generating in 10s eg
10
20
30
How do I make it
1
2
3
I am getting a problem using hibernate with postgresql
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@Column(name = "id")
private Long id;
the problem is the id is generating in 10s eg
10
20
30
How do I make it
1
2
3
As it has been pointed out, you shall use another annotation @javax.persistence.SequenceGenerator Here is how I did
@Id
@javax.persistence.SequenceGenerator(name = "order_id_sequence", sequenceName = "order_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_id_sequence")
@Column(name = "id")
Just so you know, you won't be able to rely on values from sequences not having gaps, as the database can't roll back the sequence in situations like:
So, I would advise you to either not worry about it or use a different method for producing a series of unique numbers without gaps.