The last time I made an Oracle database for the system, the strategy of using hibernate to generate the primary key was SEQUENCE, and I felt very tired at the time, because I don't know why, oracle+sequence+trigger can't get the primary key value when adding new data.
This time I will focus on this, and there are two new problems,
1。 Which hibernate strategy for generating primary keys has better performance;
2。 Primary key generation strategies should ideally be cross-database.
Everyone talks about performance, oracle uses sequence, so the primary key still wants to be generated in this way.
Then there is the primary key to return the new data
native Choose one of identity, sequence, or hilo according to the capabilities of the underlying database;
That is, the primary key is generated, which is chosen by hibernate.
Native and Denity are both database ID serial number generation strategies, Native is Hibernate is automatically selected and generated, Identity is self-selected, Identity is MySQL, SQL2000 and other database generation methods, and there is also a sequence that is Oracle and other generation methods, generally speaking, Native is automatically selected by Hibernate
For databases that support identity fields internally (DB2, MySQL, Sybase, and MS SQL), you can use identity off Key word generation. For databases that support sequences internally (DB2, Oracle, PostgreSQL, Interbase, McKoi, and SAP). DB), you can use sequence-style keyword generation. Both approaches require two times for inserting a new object SQL queries.
I checked more online information, I don't know where I saw it, this strategy of generating primary keys, if it is mysql, he will choose auto_increment way to generate the primary key; If it is Oracle, he will choose the sequence method; It's just that when using Oracle database, you need to create a hibernate_sequence, which is reserved by Hibernate, and will report an error if you don't build it (tested). |