-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: EntityManagerFactory not being injected via @PersistenceUnit
PostPosted: Tue Feb 12, 2013 5:13 am 
Newbie

Joined: Tue Feb 12, 2013 5:09 am
Posts: 1
Hello,

I'm a begginer with JPA, and I'm having problems when I use @PersistenceUnit in a servlet. EntityManagerFactory is not being injected, and I don't know why.

Code:
public class MyServlet extends HttpServlet
{   

  @PersistenceUnit
  private EntityManagerFactory emf = null;

  public MyServlet ()
  {
    super();       
  }

  @Override
  public void init(ServletConfig config) throws ServletException
  {
    super.init(config);
  }


  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Writer w = response.getWriter();
    w.append("HELLO HELLO");
    w.close();
  }

}


I've configured the persistence.xml file (inside META-INF directory) like this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="MiddlewareExpedElectrModel" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>     
    <non-jta-data-source>java:/OracleDS</non-jta-data-source>
    <class>com.ieci.mugeju.middleware.model.entities.FechaUltimaSolicitudProcesada</class>
    <properties>         
     <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
     <property name="hibernate.show_sql" value="true"/>
     <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>         
  </properties>     
</persistence-unit>


Why is not the EntityManagerFactory being injected?

I'm working with Jboss 4.2.3, and I have also configured a datasource with a oracle-ds.xml file.

If I try to get the EntityManagerFactory programatically, it works well:

Code:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MiddlewareExpedElectrModel");


But I would like to get a EntityManagerFactory instance via injection.

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.