(转)hibernate oracle 主键 自增

来源:互联网 发布:windows编程命名规则 编辑:程序博客网 时间:2024/05/16 20:29

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就会感知到此字段是通过序列来生成的。

0 0
原创粉丝点击