Does anyone know how I can do the equivalent of this in hibernate:
session.getIdentifier(instance);
with JPA?
EntityManager has a contains method but that’s pretty much it!
I’m writing some code that acts as a transformer between entities and data stored in a session (so rather than a serialized object being stored just the class name and the id is stored).
JPA 1.0 doesn’t have an equivalent so if you’re stuck with JPA 1.0, you’ll have to use Hibernate’s API: obtain the
Sessionfrom theEntityManagerand useSession#getIdentitifier(Object).For example, with JBoss (yes,
getDelegate()is not portable):If you are using JPA 2.0, then use
PersistenceUnitUtil#getIdentity(Object)as suggested by axtavt. But that’s not available in JPA 1.0.