How hibernate grows with IDs in Oracle

Source: Internet
Author: User

Citation Link: http://blog.csdn.net/w183705952/article/details/7367272

How hibernate grows with IDs in Oracle

The first: The growth strategy for setting the ID is sequence, specifying sequence's name, preferably a sequence for each table, as is the case with automatic growth in ms-sql,my-sql, without the need to create a trigger, The specific Oracle database scripts and hibernate configuration files are as follows:


[1]oracle creation script for data tables:

Java code

CREATE TABLE DEPARTMENT (

ID number (0) DEFAULT ' 0 ' not NULL,

NAME VARCHAR2 (255) is not NULL,

DESCRIPTION CLOB

);

ALTER TABLE DEPARTMENT ADD CONSTRAINT primary_0 PRIMARY KEY (ID) ENABLE;

ALTER TABLE DEPARTMENT ADD CONSTRAINT uk_department_1 UNIQUE (NAME);

CREATE SEQUENCE department_id_seq MINVALUE 10000 MAXVALUE 999999999999999999999999 INCREMENT by 1 nocycle;

Create a department table and create a separate sequence for the department table with the name Sequence_id_seq, and you do not need to create a trigger.

[Configuration of the 2]hibernate mapping file:

Java code

<?xml version= "1.0"?>

<! DOCTYPE hibernate-mapping Public

"-//hibernate/hibernate Mapping DTD 3.0//en"

"Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

="Com.liyanframework.demo.domain" >

<class name="Department" table="Department" >

<id name="id" column="id" >

<generator Class="sequence" >

<param name="sequence" >DEPARTMENT_ID_SEQ</param>

</generator>

</id>

<property name="name" column="name" type="string"/>

<property name="description" column="description" type="text"/>

</class>

How hibernate grows with IDs in Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.