@GeneratedValue four standard usages are table,sequence,identity,auto.

Source: Internet
Author: User
Tags generator
First, the JPA generic policy generator
With annotation to map hibernate entities, the annotation-based Hibernate primary key is identified as @id,
The generation rules are set by @generatedvalue. The @id and @generatedvalue here are the standard uses of JPA,
JPA provides four standard usages, which can be clearly seen by the @generatedvalue source code.

Java code @Target ({Method,field}) @Retention (RUNTIME) public @interface generatedvalue{Generat             Iontype strategy () default AUTO;         String generator () default ""; }

Among them GenerationType:

Java code public enum generationtype{TABLE, SEQUENCE, IDENTITY, AUTO}

The four standard usages provided by JPA are table,sequence,identity,auto.
Table: Use a specific database table to hold the primary key.
SEQUENCE: Generates a primary key based on the sequence of the underlying database, provided the database supports the sequence.
IDENTITY: Primary key is automatically generated by the database (mainly auto-growth type)
AUTO: The primary key is controlled by the program.

1. TABLE
Java Code @Id @GeneratedValue (strategy = generationtype.table, generator= "Payablemoney_gen") @TableGenerator (name = "PK _gen ", table=" Tb_generator ", pkcolumnname=" Gen_name ", valuecolumnname=" Gen_value ", pkcolumnvalue=" PAYABLEMOENY_PK ", allocationsize=1)

This applies the table tb_generator, defined as
SQL code CREATE TABLE tb_generator (ID number not NULL, Gen_name VARCHAR2 (255) isn't null, gen_value number not NULL, PRIMARY KEY (ID))

Insert record for generating primary key to use,
SQL code INSERT into tb_generator (ID, gen_name, gen_value) VALUES (1,PAYABLEMOENY_PK ', 1);

After the primary key is generated, the value of this record is incremented by Allocationsize.


Definition of @TableGenerator:
Java Code    @Target ({Type, method, field})     @Retention (RUNTIME)    public  @interface  TableGenerator {     string name ();      string table ()  default  "";     string catalog ()  default   "";     string schema ()  default  ";     string  pkcolumnname ()  default  "";     string valuecolumnname ()  default   "";     string pkcolumnvalue ()  

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.