【发布时间】:2016-07-16 11:28:04
【问题描述】:
如果我不想自动生成主键,我想提供带有表第一列的 ID 作为主键。
2 A
4 B
7 D
13 E
...
我希望第一列 2,4,7,13 成为表的主键。我应该只使用@Id 来做注释吗?
@Entity
public class Code {
@Id
@Column(unique=true)
private int id;
...
}
或者,如果使用@Id,主键将始终自动生成,而不是使用第一列,在这种情况下?
【问题讨论】:
-
你不需要
unique=true,如果你使用@Id。