JPA Hibernate 中 String 类型的主键 Id
作者:
当当一丢丢 | 来源:发表于
2018-04-23 00:22 被阅读1512次generation strategy
- Numerical identifier,数值型,非String类型主键,即 long、short、int
- 不指定具体策略
- Hibernate 将默认使用GenerationType.AUTO,根据底层数据库选择下面某一种
- 指定具体策略
- strategy = GenerationType.IDENTITY
- strategy = GenerationType.SEQUENCE
- strategy = GenerationType.TABL
- UUID identifier,String 类型
DEMO
----------------------------------------------------
通常是 Number 类型做主键
@Id
@GeneratedValue //不指定具体策略
@Column(name = "id", nullable = false)
private Long id;
----------------------------------------------------
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) //指定具体策略
@Column(name = "id", nullable = false)
private Long id;
----------------------------------------------------
特例 用 String 类型做主键
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Column(name = "PR_KEY")
private String prKey;
----------------------------------------------------
参考
本文标题:JPA Hibernate 中 String 类型的主键 Id
本文链接:https://www.haomeiwen.com/subject/vrahlftx.html
网友评论