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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -