Hibernate uses the oracle's sequence to generate the primary key

  

Use Hibernate for a long time, today I want to do a small example, the database uses Oracle. I intend to use the sequence in Oracle as the primary key of the table, but I don't know how to use Hibernate to associate with it. Ask a colleague, was told to use a query such as select statement "select sequence.nextval from dual",

method is as follows:

1, first create sequence2 in oracle. In your hbm. When the xml configuration is such that the data is reinserted, Hibernate automatically generates the following statement: automatically generates the next sequence value, and then inserts the object into the table. This problem is solved!

Sequence is to generate the primary key using the sequence mechanism provided by the database. For example, the Sequencenative in the oralce is generated by hibernate according to the Dialect of the database. One of the identity, hilo, and sequence is automatically used as the primary key generation method

create sequence seq_idminvalue 1start with 1increment by 1cache 20;

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

hibernate: select seq_id.nextval from dual

hibernate: insert into YXJK.T_YXJK_WHRYTXL (XM0000, ZW0000,

LXDH00, SJHM00, DZYJ00, IP0000, ID0000) values ​​(?, ?, ?, ?, ?, ?, ?)

Copyright © Windows knowledge All Rights Reserved