ORACLE:
<id name="id" column="ID">
<generator class="sequence">
<param name="sequence">DEPARTMENT_ID_SEQ</param>
</generator>
</id>
MySQL:
MSSQL:
<id name="id" type="java.lang.Integer" column="id">
<generator class="increment"></generator>
</id>
Compatible with Oracle and MSSQL hibernate:
<id name="acid" type="java.lang.Long">
<column name="ACID" precision="20" scale="0" />
<generator class="native">
<param name="sequence">SEQ_AC_CABINET</param>
</generator>
</id>
In fact, the principle is very simple. First, Hibernate will find it based on the parameters in Param. If not, the sequence number will be produced by default.
The increment primary key increments in numerical order. The implementation mechanism of this method is to maintain a variable in the current application instance to save the current maximum value, and then add 1 as the primary key each time the primary key needs to be generated. This method may cause a problem: if multiple instances access the same database, different instances may generate the same primary key because each instance maintains its primary key status, this causes duplicate primary key exceptions. Therefore, if the same database has multiple instances to access, this method must be avoided. Identity uses the primary key generation mechanism provided by the database. Such as the primary key generation mechanism in DB2, SQL Server, and MySQL. Sequence uses the sequence mechanism provided by the database to generate a primary key. For example, sequence in oralce. Native is determined by hibernate based on the underlying database and uses one of identity, Hilo, and sequence as the master node.