java - Extract the primary key from a entity object in JPA 2.0? -
let's have entity object. there way extract primary key it?
i want this:
public static object extractprimarykey(entitymanager em, object obj) { return em.givemetheprimarykeyofthisentityobject(obj); }
reason attached copy of detached entity:
public static object attach(entitymanager em, object obj) { return em.find(obj.getclass(), extractprimarykey(em, obj)); }
is possible? (i using eclipselink 2.1)
perhaps work:
em.getentitymanagerfactory().getpersistenceunitutil().getidentifier(obj);
Comments
Post a Comment