Win a copy of Murach's Python Programming this week in the Jython/Python forum!
    Bookmark Topic Watch Topic
  • New Topic

Got NullPointer exception when injecting EntityManger  RSS feed

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.
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!