java - Hibernate IDENTITY vs SEQUENCE -


"unlike identity, next number column value retrieved memory rather from disk – makes sequence faster identity" defined in article. mean id comes disk in case of identity, if yes disk , how. using sequence, can see in log, select query db while inserting new record.but didn't find select query in log in case of identity. how sequence becomes faster identity.

could please provide valuable insight complexity.

strategy used sequence:

before inserting new row, ask database next sequence value, insert row returned sequence value id.

strategy used identity:

insert row without specifying value id. after inserting row, ask database last generated id.

the number of queries same in both cases. but, hibernate uses default strategy more efficient sequence generator. in fact, when asks next sequence value, keeps th 50 (that's dafault, iirc, , it's configurable) next values in memory, , uses these 50 next values next 50 inserts. after 50 inserts, goes database 50 next values. tremendously reduces number of needed sql queries needed automatic id generation.

the identity strategy doesn't allow such optimization.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -