Short version:
Is there a simple way to get the value of a primary key after doing a merge() in Hibernate JPA?
Details:
I’m making a generic library that uses Hibernate. The library uses JPA’s merge() to serialize a POJO to the database. What’s the best way to discover the primary key’s new value? I’m assuming that the primary key will never be a composite key. However, there are cases where the POJO is a subclass of class containing the primary key. So, using reflection on the POJO isn’t an easy answer (ie it’s necessary to reflect the class and all super classes).
Any suggestions?
The Hibernate SessionFactory has methods to do this:
SessionFactory.getClassMetaData().getIdentifierPropertyName(). From there I was able to get it working.
Thanks everyone!