y150988451 发表于 2013-1-13 18:49:04

序列配置

实际开发中1和3用的比较多些

1.increment标识符适用范围
该机制不依赖于底层数据库系统,适合所有应用情况

适合单独的hibernate应用使用,不适合在集群情况下使用

OID必须为short、int、long型

<id name="id" type="long" column="person_id" > <generator class“increment"/></id>

[size=medium]2.Identity使用的情况
Identity依赖于底层数据库,需要数据库支持自动增长字段。MySQL、MSSQL、DB2、Informix、Sybase和HSQLDB

OID必须为short、int、long型

<id name="id" type="long" column="person_id" > <generator class=“identity"/></id>

3.Sequence适用范围
Sequence依赖于底层数据库,需要数据库提供对序列的支持。Oracle、DB2、PostgreSQL

OID必须为short、int、long型

<id name="id" type="long" column="person_id"><generator class="sequence"><param name="sequence">sequence_name</param> </generator></id>

4.Hilo适用的范围
Hilo不依赖于底层数据库系统。但需要在数据库系统中为其建立表。
<generator class=“hilo”><param name=“table”>A</param><param name=“column”>a</param><param name=“max_lo”>100</param></generator>

只能保证在一个数据库中生成的主键是唯一的

OID必须为short、int、long型

5.seqhilo算法(3.0新)
这种方式与hilo方式的原理是相同的,要建一个序列

该种方式对算法中的hi值的获取是通过序列完成的,而上一种是通过使用数据库表来记    录这个hi值

<id name="id" type="long" column="cat_id"><generator class="seqhilo"><param name="sequence">hi_value</param><param name="max_lo">100</param></generator></id>
6.Native适用的范围
Native会根据底层数据库系统的类型,自动选择合适的标识符生成器。适合跨数据库和    连接多种数据库情况。

OID必须为short、int、long型
页: [1]
查看完整版本: 序列配置