mysql - Hibernate: How does native identifier generation strategy work -
hibernate has identifier generation strategy called native
selects identity
, sequence
or hilo
depending upon capabilities of underlying database. used mysql hibernate.hbm2ddl.auto=update
generated id bigint(20) not null auto_increment
id
property of long
java data type.
i trying understand how did hibernate choose auto_increment
when used schemaexport
tool. auto_increment
default primary key generation strategy mysql?
could me understand it?
hibernate when selecting key generation mechanism in native mode, try choose best mechanism available in database. in case of mysql, auto increment available , hibernate uses instead of sequence, because auto increment mechanism better altough sequences work fine.
the reason why it's better it's possible in 1 single jdbc prepared statement, example insert, insert , retrieve generated key without querying database - see here further details.
in case of sequences, hibernate has first call sequence @ point , use value or result of it's use in formula populate insert key , issue insert.
the autoincrement spares roundtrip database needed increment sequence, , reason why hibernate prefers in case of mysql.
Comments
Post a Comment