users@glassfish.java.net

EntityManager, EntityManagerFactory and UserTransaction

From: <glassfish_at_javadesktop.org>
Date: Sun, 26 Jul 2009 13:26:08 PDT

Hello,

I'm having this servlet:

public class GreetingServiceImpl {

        
        @Resource
        UserTransaction userTransaction;
        
        @PersistenceUnit(unitName="test")
        EntityManagerFactory emf;
        
        public GreetingServiceImpl(){
                
                //emf = Persistence.createEntityManagerFactory("test");

......



1. I'm wondering what's the difference between having the EntityManagerFactory injected with the help of the annotation and creating it throught the call Persistence.createEntityManagerFactory("test") in the constructor.


2. Also, further in the code, what would be the difference between using the injected UserTransaction and the EntityManager's getTransaction() method.

3. When using @PersistenceContext directly (either on the class or directly on some servlet member - see http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html) is there a way to get the hand on its EntityManagerFactory?

Thanks.
[Message sent by forum member 'vladbalan' (vladbalan)]

http://forums.java.net/jive/thread.jspa?messageID=357606