Hibernate学习笔记-ID生成策略
2016-08-29 16:59
423 查看
1. xml生成id
a) generator
<id name="id" >
<generator class="native"></generator>
</id>
b) 常用四个:
(*)native:selects
upon the capabilities of the underlying database.(用native就可以让hibernate自动选择生成方式)
identity :对DB2,MySQL,
MS SQL Server, Sybase和HypersonicSQL的内置标识字段提供支持。 返回的标识符是
sequence :在DB2,PostgreSQL,
Oracle, SAP DB, McKoi中使用序列(sequence), 而在Interbase中使用生成器(generator)。返回的标识符是
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.(独一无二的编码)
2.注解方式:@GeneratedValue
a) AUTO(直接写
@GeneratedValue 相当如native)
(@GeneratedValue(strategy=GenerationType.AUTO))
i. 默认:对 MySQL,使用auto_increment
ii. 对 Oracle使用hibernate_sequence(名称固定)
b) IDENTITY(@GeneratedValue(strategy=GenerationType.IDENTITY))
c) SEQUENCE(@GeneratedValue(strategy=GenerationType.SEQUENCE))
例:
a) generator
<id name="id" >
<generator class="native"></generator>
</id>
b) 常用四个:
(*)native:selects
identity,
sequenceor
hilodepending
upon the capabilities of the underlying database.(用native就可以让hibernate自动选择生成方式)
identity :对DB2,MySQL,
MS SQL Server, Sybase和HypersonicSQL的内置标识字段提供支持。 返回的标识符是
long,
short或者
int类型的。
sequence :在DB2,PostgreSQL,
Oracle, SAP DB, McKoi中使用序列(sequence), 而在Interbase中使用生成器(generator)。返回的标识符是
long,
short或者
int类型的。
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.(独一无二的编码)
2.注解方式:@GeneratedValue
a) AUTO(直接写
@GeneratedValue 相当如native)
(@GeneratedValue(strategy=GenerationType.AUTO))
i. 默认:对 MySQL,使用auto_increment
ii. 对 Oracle使用hibernate_sequence(名称固定)
b) IDENTITY(@GeneratedValue(strategy=GenerationType.IDENTITY))
c) SEQUENCE(@GeneratedValue(strategy=GenerationType.SEQUENCE))
例:
相关文章推荐
- Hibernate学习笔记(4)ID生成策略
- Hibernate 学习笔记03 --ID生成策略
- Hibernate学习笔记_ID生成策略
- [原创]java WEB学习笔记81:Hibernate学习之路--- 对象关系映射文件(.hbm.xml):hibernate-mapping 节点,class节点,id节点(主键生成策略),property节点,在hibernate 中 java类型 与sql类型之间的对应关系,Java 时间和日期类型的映射,Java 大对象类型 的 映射 (了解),映射组成关系
- Hibernate学习笔记-ID生成策略
- Rhythmk 学习 Hibernate 03 - Hibernate 之 延时加载 以及 ID 生成策略
- Hibernate框架学习(第三讲)---Hibernate注解以及ID生成策略
- Hibernate学习笔记之主键生成策略和SchemaExport
- hibernate框架学习笔记4:主键生成策略、对象状态
- Hibernate学习——(三)ID生成策略介绍
- Hibernate 学习笔记-1-3(Hibernate的基本映射以及几种主键生成策略的测试)
- Hibernate学习笔记 -- day04 标识符、主键生成策略
- Hibernate笔记②--hibernate类生成表、id生成策略、级联设置、继承映射
- Hibernate的主键生成策略学习笔记
- Hibernate学习笔记总结(四)——缓存策略
- Follow Me:深入浅出学习Hibernate四:主键生成策略
- hibernate id 生成策略及主要使用方法
- 关于Hibernate的oracle主键id生成策略uuid、native和sequence
- Hibernate的ID生成策略/联合主键解决方案
- Hibernate中自带ID生成策略中属性“ generator”的含义