Transferred from: http://blog.163.com/wzx_dd/blog/static/1942850722012828934553/
Recently Integrated Framework, using SSH to build a framework, but after the integration, the launch of Tomcat always reported this error, the internet collected and asked colleagues, finally know the reason for the error: The database does not support automatic incrementing the primary key (Oracle does not support) so your key Generation need to be newly set
Through the Internet collection, organized a bit about the primary key self-added knowledge, for later learning to use; 1) the assigned primary key is generated by an external program and does not require hibernate participation. 2) Hilo uses the primary key generation mechanism implemented by the HI/LO algorithm, which requires additional database tables to save the primary key generation history state. 3) Seqhilo similar to Hilo, the primary key generation mechanism implemented by the HI/LO algorithm is simply that the primary key historical state is saved in sequence and is applicable to the database that supports sequence, such as Oracle. 4) The increment primary key is incremented in numerical order. The implementation mechanism of this method is to maintain a variable in the current application instance to hold the current maximum value, and then add 1 to the primary key each time a primary key is generated. The possible problem with this approach is that if there are multiple instances accessing the same database, the different instances may generate the same primary key as each instance maintains the primary key state, causing the primary key to repeat the exception. Therefore, this approach must be avoided if there are multiple instance accesses to the same database. 5) Identity adopts the primary key generation mechanism provided by the database. such as DB2, SQL Server, MySQL in the primary key generation mechanism. 6) sequence uses the sequence mechanism provided by the database to generate the primary key. such as the sequence in Oralce. 7) native by hibernate according to the underlying database to determine the identity, Hilo, sequence one of the primary key generation mode. 8) Uuid.hex is generated by hibernate based on a 128-bit unique value generation algorithm to generate a 16 binary value (encoded with a string representation of length 32) as the primary key. 9) uuid.string is similar to Uuid.hex, except that the generated primary key is not encoded (length 16). Problems (such as PostgreSQL) may occur in some databases. Foreign use the field of the external table as the primary key