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!