[jboss-user] [EJB 3.0] - Re: Why is injection not working in AS 4.0 and 4.2 (servlets

rbellia do-not-reply at jboss.com
Thu Aug 23 06:25:45 EDT 2007


JBoss 4.2.1 doen´t seem to support JPA Injection in servlets either.

Trying the same WAR i have tryed with 5 beta2, I´m facing the following problems:

The Persistence Unit is not considered automatically.
I had to manually start the EMFactory up from a Filter.init or some ServletContextListener, loading persistence.xml from WEB-INF/classes/META-INF.

The manual startutp complains some a lack of access to Transaction Managers, so I had to add the following properties in persistece.xml:


  | <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
  | <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
  | <property name="jboss.entity.manager.jndi.name" value="java:jpa/TesteJPA"/>
  | <property name="jboss.entity.manager.factory.jndi.name" value="java:jpa/TesteJPAFactory"/>
  | 


Anyway the JNDI Tree doens´t show any new entries for my JPA Componentes

The Servlet (see code below) is neither receiveing JPA Injection nor UserTransaction Injection.


  | public class ServletJPA extends HttpServlet {
  |     
  |     @PersistenceUnit(unitName="java:jpa/TesteJPAFactory") EntityManagerFactory emf;
  |     @Resource(name="java:UserTransaction") UserTransaction ut;
  |  
  |     ... doGet (...) {  
  |        doJPA();  
  |      }
  | 
  |     private String doJPA() throws NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
  |         
  |         EntityManager em = null;
  |         try {
  |             getServletContext().log("emf == null ? " + (emf == null)); // true !
  |             getServletContext().log("ut == null ? " + (emf == null)); // true !
  |             ut.begin();
  |             em = emf.createEntityManager();
  |             MyEntity x = new MyEntity(...);
  |             em.persist(x);
  |             ut.commit();
  |             return "new ID :" + x.getId();
  |         } finally {
  |             if (em != null) em.close();
  |         }
  |         
  |     }
  | 
  | 


I see comments in this thread saying that only @EJB infection is missing...
Is there something I´m missing ?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4077242#4077242

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4077242




More information about the jboss-user mailing list