Hi!
I'm implementing a generic DAO object to execute CRUD operations on objects whose classes have been mapped on Hibernate. I'm using JPA annotations for the class mapping.
In order to construct some filter expressions used internally, this DAO object needs to obtain the name of the attribute that has been mapped as the object's id for a given persistent object. So for example, I give an persistent instance (returned by a criteria query) to the DAO object and need to retrieve the name of its id attribute:
Code:
String idAttrName = daoObject.getIdAttrName(persistentObject);
...which in most cases will simply be "id", but might be something else.
Is this possible? I only have access to the entity manager originally used to retrieve the object. I don't have metamodel classes being generated.
Please let me know if you have any clues on how to obtain this information.
Thanks!
Eduardo Born