File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JBoss/WildFly and the fly likes Got NullPointer exception when injecting EntityManger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Reply locked New topic

Got NullPointer exception when injecting EntityManger

John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
I'm using JBoss 4.2.2 with Hibernate to access Oracle 10g. In my DAO class, I have:

EntityManager entityManager;


A stateless session EJB calls the DAO class.
Somehow, JBoss EJB container did not inject entity manager in my DAO
so I got a nullpointer exception when I access the entity manager.

I also tried

EntityManagerFactory entityManagerFactory;

in my DAO. EnitytManagerFactory was not injected neither.

Here is my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="" xmlns:xsi="" xsi:schemaLocation="" version="1.0">
<persistence-unit name="my_unit" transaction-type="RESOURCE_LOCAL">

my datasource file (my-ds.xml):

<?xml version="1.0" encoding="UTF-8"?>
jdbc racle:thin:@localhost:1521:XE
<!-- The driver class -->


SELECT 'new connection' FROM dual

SELECT 'connection from pool' FROM dual

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441


Let's continue this discussion in your other thread in our ORM forum, where we already have a discussion going on.

[My Blog] [JavaRanch Journal]
I agree. Here's the link:
subject: Got NullPointer exception when injecting EntityManger
It's not a secret anymore!