You might have misunderstood the meaning and usage of "session.merge()" method. It's used to MODIFY a
persisted object. That's mean, the object you are merging with should already be loaded in previous session and it is detached mode, in another word, it should already have an existing ID value for this object at this point, and no new value is generated during merge().
Your identity ID property(MySQL auto_increment in your case) is used when you go persist a new object. And if you map this right, it should be auto generated for you and you may retrieve it after object is persisted.
See
http://docs.jboss.org/hibernate/stable/ ... e-detached