I am trying use a hibernate as jpa provider in enterprise project on glassfish. I copied this libs into glassfish_home/libs:
antlr-2.7.6.jar
asm-attrs.jar
asm.jar
cglib.jar
commons-collections-3.1.jar
commons-collections.jar
commons-logging.jar
concurrent.jar
dom4j-1.6.1.jar
dom4j.jar
ehcache.jar
ejb3-persistence.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-core.jar
hibernate-entitymanager.jar
hibernate.jar
hibernate-search.jar
hibernate-validator.jar
javassist-3.4.GA.jar
javassist.jar
jta-1.1.jar
jta.jar
log4j.jar
lucene-core.jar
slf4j-api-1.5.2.jar
slf4j-api.jar
My persistence.xml :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence 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"
version="1.0">
<persistence-unit name="repo" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source >jdbc/repoPool</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="auto"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
When i deploy project, a new or updated tables are being created in database. But when i try to execute query entity manager is null;
Code:
....
@PersistenceContext(unitName = "repo")
private EntityManager em;
....
public List<User> getAll() {
List<User> result = new LinkedList<User>();
try {
String q = "select u from User u";
Query query = em.createQuery(q); //!!!!!! throws exception here; em is null
result = query.getResultList();
} catch (NoResultException nre) {
nre.printStackTrace();
} catch (RuntimeException re) {
re.printStackTrace();
}
return result;
}
What i am doing wrong?