CHANTI
CHANTI

Reputation: 1475

hibernate generator tag

What the exact purpose of ' native ' in hibernate mapping file of the generator tag ( I know by using genarator tag, it will genaerate the primarykey values ...)

....... ..........

Upvotes: 1

Views: 657

Answers (2)

fasseg
fasseg

Reputation: 17761

native means that the database's means are used to generate the primary key values. E.G. a Sequence in Oracle 10g and AUTO_INCREMENT for mysql.

Hope that helped..

Upvotes: 0

mdma
mdma

Reputation: 57707

It uses the generation strategy that is best suited for the database. From the hibernate docs:

native - selects identity, sequence or hilo depending upon the capabilities of the underlying database.

The reason this is necessary is that there is no identity type that is common to all databases. In the case where the database doesn't even support an int/long identity type, hi/lo generation strategy is necessary, which is a hibernate-generated id.

If you know the specific database you are working with, then you can name a specific identifier generation scheme to use. But for cross-db development, using native means the application has more chance of being portable across different dbs.

Upvotes: 1

Related Questions