Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
    Bookmark Topic Watch Topic
  • New Topic

Got NullPointer exception when injecting EntityManger

John King
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 10447
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator

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