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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Got NullPointer exception when injecting EntityManger

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I'm using JBoss 4.2.2 with Hibernate to access Oracle 10g. In my DAO class, I have:

....
@PersistenceContext(unitName="my_unit")
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

@PersistenceUnit(unitName="my_unit")
EntityManagerFactory entityManagerFactory;

in my DAO. EnitytManagerFactory was not injected neither.



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="my_unit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:/OracleTestDS</non-jta-data-source>
</persistence-unit>
</persistence>

my datasource file (my-ds.xml):

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>OracleTestDS</jndi-name>
<connection-url>
jdbc racle:thin:@localhost:1521:XE
</connection-url>
<!-- The driver class -->
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>uid</user-name>
<password>pw</password>
<min-pool-size>1</min-pool-size>
<max-pool-size>3</max-pool-size>

<idle-timeout-minutes>15</idle-timeout-minutes>

<new-connection-sql>
SELECT 'new connection' FROM dual
</new-connection-sql>

<check-valid-connection-sql>
SELECT 'connection from pool' FROM dual
</check-valid-connection-sql>

<track-statements/>
<metadata>
<type-mapping>Oracle10g</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
John,

Let's continue this discussion in your other thread in our ORM forum, where we already have a discussion going on.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    Bookmark Topic Watch Topic
  • New Topic