Hibernate annoation (three-ID generator)

Source: Internet
Author: User
Tags generator uuid

ID Generation:

ID generator visible code not available within hibernate

Using @generatedvalue

1 can be used at the same time for different databases

  @Id
    @GeneratedValue(strategy = GenerationType.AUTO)

2 for MySQL

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)

3 for Oracle

  @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE,generator="s_gen")
    @SequenceGenerator(name="s_gen",sequenceName="s_seq")

Description: The Strategy property of @GeneratedValue () supports the ID generator in 5: In addition to the above 3 Chinese and foreign generationtype.table

2 with the use of @genericgenerator not used alone

ID generator visible code not available within hibernate

GENERATORS.put( "uuid", UUIDHexGenerator.class );
 GENERATORS.put( "hilo", TableHiLoGenerator.class );
 GENERATORS.put( "assigned", Assigned.class );
 GENERATORS.put( "identity", IdentityGenerator.class );
 GENERATORS.put( "select", SelectGenerator.class );
 GENERATORS.put( "sequence", SequenceGenerator.class );
 GENERATORS.put( "seqhilo", SequenceHiLoGenerator.class );
 GENERATORS.put( "increment", IncrementGenerator.class );
 GENERATORS.put( "foreign", ForeignGenerator.class );
 GENERATORS.put( "guid", GUIDGenerator.class );
 GENERATORS.put( "uuid.hex", UUIDHexGenerator.class ); // uuid.hex is deprecated
 GENERATORS.put( "sequence-identity", SequenceIdentityGenerator.class );
)

If you want different tables to use the same primary key generator, you can set the Name property of his generator to the same

For example:

@GeneratedValue(name="id1")
@GenericGenerator(name="id1",strategy="identity")

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.