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