Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Got NullPointer exception when injecting EntityManger

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

Posts: 10445
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.
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic