My question concerns EntityManager.getReference. Given that I am in one JPA session, can I be sure that for two calls to EntityManager.getReference for the same entity and the same primary key I always get the same instance of java object ? For two distinct sessions I'd suspect to get two different instances of java objects - is it really the case ?
I am interested to know the general rule, not how any specific implementation works. Is it defined by the spec or not ? (I was unable to find it out myself).
Person p1 = EntityManager.getReference(Person.class, 1L);
Person p2 = EntityManager.getReference(Person.class, 1L);
if (p1 == p2) {
System.out.println("SAME");
} else {
System.out.println("DIFF");
}