EntityManager not injected and nullpointer
ordeal Apr 4, 2011 11:28 PMHello
I have a simple Ejb application consisting of 3 entities and 3 stateless SB, web tier is based on a jsp page which accesses the DB making some simple operations.
The application has been deployed as an ear file to jboss-5.1.0.GA.
The only jar on default/lib directory is the mysql connector mysql-connector-java-5.1.15-bin.jar, used to map queries to a mysql dbms.
Here is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?> <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="SampleProjectUnit" > <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/MyDB</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> </properties> </persistence-unit> </persistence>
The Error i get from logs is java.lang.NullPointerException while invoking em.createQuery, where em is my container-managed entity manager, using jdpa i can see em as a null pointer, as not being injected.
This is the SB where i call the entitymanager :
@Stateless @TransactionManagement(TransactionManagementType.CONTAINER) public class PublisherDAOBean implements PublisherDAO { @PersistenceContext(unitName = "SampleProjectUnit")EntityManager em; @SuppressWarnings("unchecked") public List<Publisher> findAllPublishers() { return em.createQuery("SELECT a FROM Publisher a" ).getResultList(); // here i get the nullpointer exception } ...
Can anyone tell me how to solve this issue ?
Thanks, Rino
Attached files:
Progetto_EJB3.ear is the app as deployed to jboss
source.zip contains the source files
server.log is the jboss log from server startup
-
server.log.zip 6.0 KB
-
source.zip 7.0 KB
-
Progetto_EJB3.ear 1.3 MB