using oracle-sequence hibernate

2010-04-23  来源:本站原创  分类:Database  人气:417 

1. To create a growth from the segment table, there are two, one is to use a different table each Sequence, as follows:

1, first create a sequence in Oracle sequence

create sequence seq_id
minvalue 1
start with 1
increment by 1
cache 20;

2. Hbm.xml in the configuration of your


<id column="ID0000" name="id" type="integer">
<generator class="sequence">
<param name="sequence">seq_id</param>
</generator>
</id>

This data, when re-inserted, Hibernate automatically generates the following statement:


hibernate: select seq_id.nextval from dual
hibernate: insert into YXJK.T_YXJK_WHRYTXL (XM0000, ZW0000, LXDH00, SJHM00, DZYJ00,
IP0000, ID0000) values (?, ?, ?, ?, ?, ?, ?)

Automatically generate the next sequence value, then insert an object into the table. Note that when in use, Hibernate for the sequence of the primary key requirement is that it must be a shor, long, or integer.

2 Another way is to use public sequence

This is the time you can not use the specified table sequence, then the corresponding hbm.xml in are:

<id column="ID0000" name="id" type="integer">
<generator class="native">
</generator>
</id>

Then create a shared sequence object, named hibernate_sequence

create sequence hibernate_sequence
minvalue 0
maxvalue 99999999
start with 10000
increment by 1;

3 Notes

If the database is a database migration from sqlserver from other, then create a sequence when the initial value should be higher than the current maximum ID value in the table a large, otherwise an error, because the sequence does not maintain it and in front of the existing guidance value to repeat.

1, sequence: used for Oracle database

<id name="id" column="id">
<generator class="sequence">
<param name="sequence"> Sequence name </param>
</generator>
</id>

2, native: cross-database use, from the bottom of Dialect.

Default.sequence As hibernate_sequence
<id name="id" column="id">
<generator class="native"/>
</id>

Note: When using the native Hibernate by default to find the Oracle of hibernate_sequence sequence. If Oracle is not the sequence, even when the Oracle database error.

相关文章
  • Use the oracle sequence hibernate 2011-03-31

    First, in many cases, we use Hibernate in the database has been created on the basis of. In oracle, if already created the database using the sequence, you can follow the steps below it in the introduction to Hibernate: 1, first create a sequence in

  • use with oracle sequence hibernate problems 2011-03-12

    Usual number field is often used in the project type, using the hibernate process found a strange problem <generator> <param name="sequence"> seq_customer </ param> </ Generator> Automatic way using a database sequence, i

  • Hibernate Oracle sequence的使用技巧 2013-11-01

    本文介绍了关于Hibernate中如何使用Oracle sequence的问题以及应注意的事项. 一.为表创建自增长自段有两种,一种是不同的表使用各自的Sequence,方法如下: 1.在Oracle sequence首先创建sequence create sequence seq_idminvalue 1start with 1increment by 1cache 20; 2.在你的hbm.xml中的配置 seq_id 这样再插入数据的时候,Hibernate会自动生成如下语句: hiber

  • Oracle and Hibernate problems 2010-12-20

    I found Oracle (Oracle Corporation) is not so cool with it (compared with Mysql and Sqlserver2000), Oracle database primary key sequences with the Sequence control, Mysql and Sqlserver2000 auto-increment is used to automatically increment the primary

  • ORACLE Sequence from growth 2010-05-13

    Sequence is a database system according to certain rules automatically increase the number of sequences. This sequence usually the primary key as the agent (because it would not repeat), no other meaning. Sequence characteristics of the database syst

  • Since the increase in the field to create ORACLE (sequence) of the method 2010-07-15

    Since the increase in the field to create ORACLE, sequence Introduction: Achieved by creating a series of brief ORACLE SEQUENCE sequence in oracle in the so-called serial number, each check will automatically increase when it is generally required by

  • Oracle sequence to use: Create. Delete 2010-08-13

    copy from [http://database.51cto.com/art/201004/196359.htm] Explained at the beginning to use Oracle sequence before plus a little on the Oracle client sqlplus use, that is, if the implementation of multi-line statement, then we must add "/" to

  • Oracle sequence sequence of usage 2010-09-24

    Oracle sequence sequence of usage oracle There is no increment type of field, so usually need to define a sequence Automatically increase as the data type field . Then record some information about the oracle sequence , Has been used for reference !

  • ORACLE SEQUENCE simple example scene 2010-10-11

    A simple example using the ORACLE SEQUENCE Sequence (SEQUENCE) is the serial number generator, table rows can be automatically generated sequence number, resulting in a set of equally spaced values (type numbers). Its main purpose is to generate the

  • About oracle sequence 2010-09-25

    sequence is the oracle of the increment sequence. oracle need to create the increment sequence. oracle sequence for all tables in the summary table in user_sequences, select * from user_sequences where sequence_name = 'EMP_SEQUENCE' (Note that the se

  • Sequences oracle sequence handy 2011-03-07

    Sequences oracle sequence handy 1. Plsql can interface directly with a new Sequences, without writing code, so if you want to see the code, the lower right corner there is a view of SQL, it is convenient. 2 queries SELECT SEQ_Name.NEXTVAL FROM DUAL T

  • Oracle: sequence id to achieve self-growth 2011-03-10

    First, you need to have a table! CREATE TABLE example ( ID Number (4) NOT NULL PRIMARY KEY, NAME VARCHAR (25), PHONE VARCHAR (10), ADDRESS VARCHAR (50)); Then you need a custom sequence CREATE SEQUENCE emp_sequence INCREMENT BY 1 - plus a few each ST

  • Oracle: sequence usage 2011-06-28

    Oracle: sequence usage in the Oracle database, sequence the same as serial numbers, each taking the time sequence will be automatically increased, usually acting on the sort required by the serial number of the place. 1, Create Sequence (Note: You ne

  • oracle sequence语句重置方介绍 2014-08-11

    在开发过程中,可能会用到oracle sequence语句,本文以oracle sequence语句如何重置进行介绍,需要的朋友可以参考下 在开发过程中,可能会用到oracle sequence语句,本文以oracle sequence语句如何重置进行介绍,需要的朋友可以参考下 Oracle重置sequence语句1 Sql代码 DECLARE n NUMBER(10 ); tsql VARCHAR2(100 ); p_seqName varchar2(20 ); BEGIN p_seqName

  • Oracle sequence in Hibernate since the increase in the allocation method 2010-02-18

    In many cases, we use Hibernate in the database has been established on the basis of good. In oracle, if well-established use of the database sequence, you can follow the following steps to get it into Hibernate in: 1, first create a sequence in orac

  • Oracle in hibernate primary key to achieve self-growth strategy 2010-04-01

    In many cases, we use Hibernate in the database has been established on the basis of good. In oracle, if well-established use of the database sequence, you can follow the following steps to get it into Hibernate in: 1, first create a sequence in orac

  • Since the increasing sequence ORACLE SEQUENCE 2010-06-24

    In the oracle of the serial number sequence is called each time when it will be automatically taken to increase, generally used in the serial number required by the sort of place. 1, Create Sequence The first thing you need or CREATE ANY SEQUENCE CRE

  • Oracle in hibernate primary key to achieve self-growth strategy (transfer) 2010-09-15

    In many cases, we use Hibernate in the database has been established on the basis of good. In oracle, if well-established use of the database sequence, you can follow the following steps to get it into Hibernate in: 1, first create a sequence in orac

  • Oracle and Hibernate problem 2010-12-20

    I found Oracle (Oracle Corporation) not so cool with them (compared with Mysql and Sqlserver2000), Oracle database primary key sequences with Sequence control, Mysql and Sqlserver2000 auto-increment is used to automatically increment the primary key

  • Oracle in hibernate to achieve the automatic growth 2011-10-27

    According to the hibernate documentation, there are two ways to achieve the entity object's primary key auto-growth. The first: the growth strategy is to set the ID sequence, while the name of the specified sequence, it is best to build a table for e