I’m using Hibernate to access MySQL, and I have a table with an auto-increment primary key.
Everytime I insert a row into the table I don’t need to specify the primary key. But after I insert a new row, how can I get the relative primary key immediately using hibernate?
Or I can just use jdbc to do this?
When you save the hibernate entity, the
idproperty will be populated for you. So if you haveI actually almost always do an
assertNotNullon the id of a persisted entity in my tests to make sure the save worked.