yunshi tan [
https://community.jboss.org/people/yunshi] created the discussion
"@PersistenceContext is null in jboss7"
To view the discussion, visit:
https://community.jboss.org/message/759623#759623
--------------------------------------------------------------
Hi all,
I am migrating jboss4.2.3 -> jboss7 and I am totally blocked by the probleme that
@PersistenceContext always returns me NULL in the EJB jars.
Here are the projects in my deployment :
deployment
-----------------------------
- hibernate-ejb-1.jar
| - src/main/java ... some entities and DAO
| - src/main/resources
| - META-INF
| - hibernate.cfg.xml
| - persistence.xml
- seam2App.ear
| - module1.jar
| - module2.jar
| - war1.war
hibernate-ejb-1.jar offers some DAO functions for my seam2App.ear and other
applications. *However, in hibernate-ejb-1.jar, all the @PersistenceContext EntityManager
returns NULL.*
*Here is the persistence.xml*
<persistence xmlns="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="xxx-unit"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/xxxxxDS</jta-data-source>
<properties>
<property name="hibernate.ejb.cfgfile"
value="/META-INF/hibernate.cfg.xml"/>
<property name="jboss.entity.manager.factory.jndi.name"
value="java:jboss/EntityManagerFactories/xxx"/>
<property name="hibernate.session_factory_name"
value="java:jboss/hibernate/SessionFactoryxxx"/>
<property name="jboss.as.jpa.providerModule"
value="org.hibernate:3" />
</properties>
</persistence-unit>
</persistence>
In the *cosole*, I have
12:15:49,752 INFO
[org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC
service thread 1-2) JNDI bindings for session bean named xxxDAOImpl in deployment unit
deployment "xxxxxxx-SNAPSHOT.jar" are as follows:
java:global/xxxxxx-SNAPSHOT/xxxxxxDAOImpl!com.xxxx.dao.common.remotexxxxxxDAORemote
java:app/xxxxxx-SNAPSHOT/xxxxxxDAOImpl!com.xxxxxx.dao.common.remote.xxxxxxDAORemote
java:module/xxxxxxDAOImpl!com.xxxxxx.dao.common.remote.xxxxxxDAORemote
java:jboss/exported/xxxxxx-SNAPSHOT/xxxxxxDAOImpl!com.xxxxxx.dao.common.remote.xxxxxxDAORemote
java:global/xxxxxx-SNAPSHOT/xxxxxxDAOImpl!com.xxxxxx.dao.common.local.xxxxxxDAOLocal
java:app/xxxxxx-SNAPSHOT/xxxxxxDAOImpl!com.xxxxxx.dao.common.local.xxxxxxDAOLocal
java:module/xxxxxxDAOImpl!com.xxxxxx.dao.common.local.xxxxxxDAOLocal
In other applications who depend on hibernate-ejb-1.jar, I tried to get the Ejb like
this:
context = new InitialContext();
DAO dao= (DAO ) context.
lookup("java:global/xxxxxx-SNAPSHOT/xxxxxxDAOImpl!com.xxxxxx.dao.common.local.xxxxxxDAOLocal");
*DAO.java looks like this*
@Stateless
public class DAOImpl implements DAOLocal, DAORemote{
@PersistenceContext
private EntityManager entityManager;
public List<Bean> findAll() {
Query query = createNamedQuery(Bean.FIND_ALL);
if(query!=null)
return query.getResultList();
return null;
}
}
However, I have the NPE because @PersistenceContext EntityManager entityManager is
always null.
The probleme is :
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/759623#759623]
Start a new discussion in JBoss AS 7 Development at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]