Let's say we have an entity object. Is there a way to extract a primary key from it?
I want to do something like this:
public static Object extractPrimaryKey(EntityManager em, Object obj) {
return em.giveMeThePrimaryKeyOfThisEntityObject(obj);
}
Reason for that is to get an attached copy of detached entity:
public static Object attach(EntityManager em, Object obj) {
return em.find(obj.getClass(), extractPrimaryKey(em, obj));
}
Is it possible? (I am using EclipseLink 2.1)