GenerationType.AUTO vs GenerationType.IDENTITY in hibernate

sethu palaniyappan picture sethu palaniyappan · Oct 13, 2015 · Viewed 42.2k times · Source

Currently we are using mysql as a database and we use

@Generated Value(strategy = GenerationType.IDENTITY)

It's working perfectly at certain situation we need to migrate our database to Oracle at that time it's not working properly.If any one knows what's actual difference present behind this and how it's working?

Answer

Neil Stockton picture Neil Stockton · Oct 13, 2015

How could it "work properly" (you don't define basic info like what you mean by that) with Oracle ? I don't see the relevance of AUTO to your question - that simply lets an implementation choose what it wants to use.

"IDENTITY" (as per JPA javadocs and spec - what you should be referring to) means autoincrement. There is no such concept in Oracle, yet there is in MySQL, SQLServer and a few others. I would expect any decent JPA implementation to flag an error when even trying such a thing.

Oracle would allow "SEQUENCE", or "TABLE" strategies to be used however