" I use Jboss EAP 6.4.7 and the application needs to access datasource configured in Jboss which uses H2 database. The EntityManager is not set in the DAO layer and is returning null. I appreciate any help in correcting or suggesting any idea. Unfortunately the application does not use Spring context and it will be plain JPA-Hibernate model to access the database."
Below is the standalone.xml extract.
<datasource jta="false" jndi-name="java:/ecmConfigDS" pool-name="ecmConfigDS" enabled="true" use-ccm="true">
<connection-url>jdbc:h2:tcp://localhost/~/ecmconfig</connection-url>
<driver-class>org.h2.Driver</driver-class>
<driver>h2</driver>
<security>
<user-name></user-name>
</security>
</data source>
persistence.xml
<persistence-unit name="ecmFunctionalRoute">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:/ecmConfigDS</non-jta-data-source>
<class>gov.ny.otda.ecm.sharedservices.dao.entity.FunctionRoute</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
DAO.java
@PersistenceContext(unitName="ecmFunctionalRoute")
private EntityManager entityManager;
public E findByID(Long ID) throws DAOException {
return entityManager.find(entityClass, ID);
}