The OID of Hibernate

Source: Internet
Author: User

In the relational database,primary key to identify recordsand ensure the uniqueness of daily Records. In the Java language, the memory addresses of the objects referenced by the two variables are compared, or the objects referenced by the two variables are compared for equality.Hibernate to resolve the differences between the two, use the object identifier (OID) to identify the uniqueness of the object。OID is the equivalent of a primary key in a relational database in the Java object Model。 At run time, Hibernate maintains the corresponding relationship between the Java object and the database based on the OID. As shown below:
Transaction tx = Session.begintransaction ();
User User1 = (user) session.load (user.class,new Long (1));
User User2 = (user) session.load (user.class,new Long (1));
User User3 = (user) session.load (user.class,new Long (3));
When the application executes the above code, the first OID is 1 object, looks up the record with ID 1 from the database, then creates the desired user instance, saves it to the session's cache, assigns the reference of the instance to the variable user1, and loads the OID 1 object for the second time. Directly assigns a reference to the instance of the OID in the session cache to User2, so the result of User1=user2 is true


Hibernate's object identifier (OID)
You can use the <id> element to set the oid,oid can be defined as the Short,int,long type, and by default, hibernate will define the OID as the Java wrapper type when the persistence class is generated
Use the <generator> child element in the ID element to set the identifier generator, for example:
<id type= "Long" column= "id" >
<generator/>
</id>
The following is a built-in identifier generator provided by Hibernate:
1.increment
2.identity
3.sequence
4.hilo
5.native
6.uuid
7.assigned

The OID of Hibernate

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.