You can use EntityManagerFactory within a JEE app. It is not encouraged though. It is much easier, IMO, to let the container manage the lifecycle of the EntityManager.
I see...but what you are saying is that i must control the entitymanagers lifecycle myself?
Why i'm asking is because in the spec (se quote above) it says quite the opposite - or is that me interpreting the text wrong?
Your interpretation is correct. You can use getEntityManager() to obtain a JTA-enabled EntityManager whose lifecylce is managed by the container.
Still, even if you are only using servlets and not using EJBs, why would you ever want to use the factory? Really, the only reason to use EMF within an app server is when you are *not* using EJB and want an EXTENDED persistence context.
Well ..the reason is not that I want to use it - it's because i'm forced to do it, since it seems to be the only way to dynamicly change entitymanager on the fly without having to declare them in the code.
See again the ongoing discussion:
If I could solve that issue without using EMF no one would be more happy than me...