wood burning stoves 2.0*
The moose likes JBoss/WildFly and the fly likes Got NullPointer exception when injecting EntityManger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Reply locked New topic
Author

Got NullPointer exception when injecting EntityManger

John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
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

Joined: Jul 20, 2005
Posts: 10262
    
168

John,

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


[My Blog] [JavaRanch Journal]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Got NullPointer exception when injecting EntityManger