This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19696|Reply: 2

[Source] nhibernate native primary key generation policy

[Copy link]
Posted on 4/7/2017 10:02:04 AM | | |

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).




Previous:Summary of the execution order of static, non-static, and constructive methods in a class
Next:Handling concurrent Timestamp and ConcurrencyCheck distinction
 Landlord| Posted on 4/7/2017 10:02:07 AM |
Native is innate, native, which means it is innate.
That means it is automatically generated and does not require manual help or control.

Assigned means designated, assigned.
If you don't give him something, then he can't achieve it.
It takes labor, give it something yourself
So it's assigned
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com