Use Hibernate to automate the growth of Oracle (ID per table)

Source: Internet
Author: User

The growth strategy for setting the ID is sequence, specifying sequence's name, preferably one for each table sequence
For example, create a sequence:
CREATE SEQUENCE department_id_seq MINVALUE 10000 MAXVALUE 999999999999999999999999 INCREMENT by 1 nocycle;
Configuration of Hibernate mapping files:

  • <?xml version= "1.0"?>
  • <! DOCTYPE hibernate-mapping Public
  • "-//hibernate/hibernate Mapping DTD 3.0//en"
  • "Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
  • <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>

  • In the Hibernate mapping file, select sequence for the ID generation policy, specify sequence's name Department_id_seq, and hibernate will automatically get department_id_ when you save the new object. SEQ. Nextval is saved to the database as the ID of the new object, so you do not need to use the trigger again to generate the ID of the new record.

Use Hibernate to automate the growth of Oracle (ID per table)

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.