我尝试使用复合键-但是:
基本上我想做的是使每行(板链接)具有唯一的顺序,如下所示:
+---------+-----------+------------+
| post_id | thread_id | board_link |
+---------+-----------+------------+
| 1 | 1 | board_1 |
| 2 | 1 | board_1 |
| 3 | 1 | board_1 |
| 1 | 2 | board_2 |
| 2 | 2 | board_2 |
| 3 | 3 | board_2 |
+---------+-----------+------------+
我正在使用Spring Boot 2.2.6.RELEASE,PostgreSQL 12.3-2(9.6 testcontainers)和6.3.2 flyway-core。全部通过gradle。
答案 0 :(得分:1)
您可以使用GeneratedValue
批注并将策略设置为GenerationType.SEQUENCE
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id", updatable = false, nullable = false)
private Long id;