On further investigation I discovered that my keys were not being regenerated, but rather my update method was inserting new rows into the database. The problem was that I was retrieving an Object from the database, closing the session, displaying it in the UI, and then opening a new session and calling session.save(object) to write it back to the database. Changing session.save(object) to session.saveOrUpdate(object) fixed my problem. Unfotunately, the book I used to learn Hibernate did not give examples of using saveOrUpdate but this was explained in detail in the Hibernate documentation.
|