[英]hibernate postgres id incrementing in 10s
我在使用休眠與Postgresql時遇到問題
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@Column(name = "id")
private Long id;
問題是id在10s內生成,例如
10
20
30
我該怎么做
1
2
3
另請參見- 休眠oracle序列會產生較大的差距
正如已經指出的那樣,您應該使用另一個注釋@ javax.persistence.SequenceGenerator這是我的工作方式
@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")
請注意,由於數據庫無法在以下情況下回滾序列,因此您將無法依賴序列中沒有間隔的值:
因此,我建議您不要擔心,也可以使用其他方法來產生一系列沒有間隙的唯一數字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.