hibernate ID生成策略配置
2016-03-01 14:17
405 查看
1.Student.hbm.xml配置
uuid
uses a 128-bit UUID algorithm to generate identifiers of type string that are unique within a network (the IP address is used). The UUID is encoded as a string of 32 hexadecimal digits in length.
id的类型要为String类型,最终在mysql中产生的id为varchar类型。
selects
upon the capabilities of the underlying database.
2.Annotation配置_IDENTITY_SEQUENCE
Sequence生成器,使用oracle数据库。
@SequenceGenerator(name=”teacherSEQ”,sequenceName=”teacherSEQ_DB”)加在类前
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator=”teacherSEQ”)加在方法前
3.TableGenerator(跨数据库平台)
@javax.persistence.TableGenerator(
name="Teacher_GEN",
table="GENERATOR_TABLE",
pkColumnName="pk_key",
valueColumnName="pk_value",
pkColumnValue="Teacher",
allocationSize=1
)
<hibernate-mapping package="com.wxh.hibernate.model"> <class name="Student" > <id name="id"> <generator class="uuid"></generator> </id> <property name="age"></property> <property name="name"></property> </class> </hibernate-mapping>
uuid
uses a 128-bit UUID algorithm to generate identifiers of type string that are unique within a network (the IP address is used). The UUID is encoded as a string of 32 hexadecimal digits in length.
id的类型要为String类型,最终在mysql中产生的id为varchar类型。
<hibernate-mapping package="com.wxh.hibernate.model"> <class name="Student" > <id name="id"> <generator class="uuid"></generator> </id> <property name="age"></property> <property name="name"></property> </class> </hibernate-mapping>
native
selects
identity,
sequenceor
hilodepending
upon the capabilities of the underlying database.
2.Annotation配置_IDENTITY_SEQUENCE
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) public int getId() { return id; }
Sequence生成器,使用oracle数据库。
@SequenceGenerator(name=”teacherSEQ”,sequenceName=”teacherSEQ_DB”)加在类前
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator=”teacherSEQ”)加在方法前
3.TableGenerator(跨数据库平台)
@javax.persistence.TableGenerator(
name="Teacher_GEN",
table="GENERATOR_TABLE",
pkColumnName="pk_key",
valueColumnName="pk_value",
pkColumnValue="Teacher",
allocationSize=1
)
相关文章推荐
- 52. N-Queens II
- IOS开发 strong,weak,retain,assign,copy nomatic 等的区别与作用
- linux - 文件查找及压缩
- 检查浏览器
- 高等数学:第一章 函数与极限(3)无穷小 连续性 间断点 连续函数
- 栈应用——单词逆序
- JAVA泛型
- 使用bindview自动安装passthru驱动的调试笔记
- 启动页适配
- ZOJ 2781-Rounders
- 性能问题初步排查方法
- ORA-12514(TNS:监听程序当前无法识别...)
- 前端之JavaScript第二天学习(5)-JavaScript-语句
- 2.4.3 顶层const
- 应用上传不成功
- new Date()和System.currentTimeMillis()获取当前时间戳
- 客戶教我的事:真正的「好服務」不能只靠專業,還要做到這個關鍵
- Assigning to 'id<xxxxDelegate>' from incompatible type 'xxxxViewController *const __strong'
- 给一个类增加xib文件
- Android可动态改变compoundDrawable颜色的TextView