find « EntityManager « JPA Q&A

1. When to use EntityManager.find() vs EntityManager.getReference()

I have come across a situation (which I think is weird but is possibly quite normal) where I use the EntityManager.getReference(LObj.getClass(), LObj.getId()) to get a database entity and then pass the ...

2. what is difference between EntityManager.find() and EntityManger.getReference()?

Whats is the difference between

<T> T EntityManager.find(Class<T> entityClass, Object primaryKey) and 
<T> T EntityManager.getReference(Class<T> entityClass, Object primaryKey) 
? I think getReference returns entity if it is managed. and find returns entity if ...

3. Ejb3Configuration.addPackage() does not find entities

I want to add known JPA entities programatically when creating EntityManagerFactory. So I have this sequence (Hibernate 3.6)

 Ejb3Configuration ejbConf = new Ejb3Configuration();
 ejbConf.configure("TestPU", null);
 emf = ejbConf.buildEntityManagerFactory();
I also tried ...

4. EntityNotFoundException on EntityManager.find is against JPA

... Caused by: javax.persistence.EntityNotFoundException: Unable to find es.qrr.buda.dao.impl.jpa.user.UserEntity with id 1234321 at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound( [:3.6.6.Final] at org.hibernate.event.def.DefaultLoadEventListener.returnNarrowedProxy( [:3.6.6.Final] at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad( [:3.6.6.Final] at org.hibernate.event.def.DefaultLoadEventListener.onLoad( [:3.6.6.Final] at org.hibernate.impl.SessionImpl.fireLoad( [:3.6.6.Final] at org.hibernate.impl.SessionImpl.get( [:3.6.6.Final] at org.hibernate.impl.SessionImpl.get( [:3.6.6.Final] at org.hibernate.ejb.AbstractEntityManagerImpl.find( [:3.6.6.Final] ...

5. EntityManager find() problem

Dear all, I have a Site bean that have a Warehouse (@OneToOne relationship) When I persist an instance of Site and find this instance sometimes the Warehouse relationship comes null and sometimes come whith value. Maybe is a session problems, beacause if I restart the application, the find never fails. Can anybody help me? tks,