Win a copy of Design for the Mind this week in the Design 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:

....
@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>
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic