hibernate oracle 主键 自增

 

Hibernate 实现对oracle 数据库表ID的自动增长

 

1:建表

Create      table        test_table       (

id      integer     not null primary key ,

name       varchar2(20)

         )

2:建序列

Create      sequence          test_table_seq

start  with    1

increment  by 1

minvalue           1

maxvalue          999999999999

nocycle

nocache;

 

3:Hibernate 映射文件 testtable.hbm.xml

 

                            sequence">

                                     test_table_seq

                           

  

4:与SQLSERVER 主键生成方式对比

                            native"/>

         当然对于sqlserver 来说主键的生成方式也可以是:increment

总结:

1:创建表和序列且测试序列是否能正常工作,确保序列的正确性;

2:hibernate 中 主键的生成方式为上面红色的部分,这样hibernate就会感知到此字段是通过序列来生成的。

 

以上已经通过测试。

 

 

你可能感兴趣的:(hibernate,oracle,sqlserver,generator,table,integer,Hibernate,Mysql,or,SQLServer,or,Oracle)