> I implemented a Session Bean,
if the bean is stateless, it will result into frequent construction of EMF . 

> Which good practise do you propose?
construction of EMF is 'heavy' operation. You should avoid it all cost.
Implement a mechanics where EMF is created only once during the lifetime of
an application.


Scherer, Annette wrote:
> 
> Hello,
> 
> I use OpenJPA in a distributed J2EE Environment. I implemented a Session
> Bean, which lazy creates EntityManager and EntityManager Factory:
> 
> private EntityManager getEm() {
>       if (this.em == null) {
>               this.em = this.getEmf().createEntityManager();  
>       }
>       return this.em;
> }
> 
> private EntityManagerFactory getEmf() {
>       if (this.emf == null) {
>               this.emf = 
> Persistence.createEntityManagerFactory("Selektionen_DB");
>       }
>       return this.emf;
> }
> 
> I persisted simple test objects with em.persist(...). Following calls with
> em.find(....) failed in following constellation
> - persist on clone 1 
> - find on clone 2
> 
> 
> 
> When creating EntityManager on each call (see code fragment below, without
> lazy init), it works fine. But that connat be best practice, because I
> suppose, this approach ist not as performant, it needs to be.
> 
> private EntityManager getEm() {
>       this.em = this.getEmf().createEntityManager();  
>       return this.em;
> }
> 
> private EntityManagerFactory getEmf() {
>       if (this.emf == null) {
>               this.emf = 
> Persistence.createEntityManagerFactory("Selektionen_DB");
>       }
>       return this.emf;
> }
> 
> 
> Which good practise do you propose?
> 
> 
> Thank you for support
> Annette Scherer
> Abteilung Informatik
> 
> 
> 


-----
Pinaki 
-- 
View this message in context: 
http://n2.nabble.com/EntityManager-in-Application-Server-Clusters-tp3342755p3345304.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to