Hibernate ID Generation policy configuration

Source: Internet
Author: User

1.student.hbm.xml Configuration


Uuid

Uses a 128-bit UUID algorithm to generate identifiers of type String that's unique within a network (the IP address is U SED). The UUID is encoded as a string of hexadecimal digits in length.


The ID must be of type string. Finally, the ID generated in MySQL is a varchar type.



native

Selects identity , sequence or hilo depending upon the capabilities of the underlying database.


2.Annotation Configuration _identity_sequence

@Id @generatedvalue (strategy=generationtype.identity) public int getId () {return Id;}


Sequence generator, using the Oracle database.

@SequenceGenerator ( name= "Teacherseq", Sequencename= "teacherseq_db") added in front of class

@GeneratedValue(strategy=generationtype.sequence,generator="Teacherseq") added before the method


3.TableGenerator (cross-database platform)

@javax. Persistence.tablegenerator (

Name= "Teacher_gen",

Table= "Generator_table",

Pkcolumnname= "Pk_key",

Valuecolumnname= "Pk_value",

Pkcolumnvalue= "Teacher",

Allocationsize=1

)


Student.hbm.xml

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "Http://www.hibernate.org/dtd/hiberna Te-mapping-3.0.dtd ">
  
Teacher.hbm.xml

<?xml version= "1.0" encoding= "UTF-8"?

><! DOCTYPE hibernate-mapping public "-//hibernate/hibernate mapping DTD 3.0//en" "Http://www.hibernate.org/dtd /hibernate-mapping-3.0.dtd ">


Hibernate ID Generation policy configuration

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.