Topic
  • No replies
SystemAdmin
SystemAdmin
783 Posts

Pinned topic Got NullPointer exception when injecting EntityManger

‏2012-07-03T09:30:23Z |
hi,
In my DAO class, I have:
***************************************
@PersistenceContext(unitName="OVO")
private EntityManager em;
public long getSeuilToilettage() {

if(em==null)
System.out.println("***EM null!!!");
String queryString ="select valeur from CHEQUES.T_PARAMETRE where CODE_PARAM='001'" ;
return Long.parseLong((String)em.createNativeQuery(queryString).getSingleResult());

}
***************************************
Somehow, CG did not inject entity manager in my DAO so I got
a nullpointer exception when I access the entity manager.and i get the "EM null!!!" msg

here my persistence.xml
***************************************
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
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">

<persistence-unit name="OVO" transaction-type="JTA">

<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/PS2</jta-data-source>

<class>ma.eai.ovo.TCommentaire</class>
<class>ma.eai.ovo.TCommentaireGestOper</class>
<class>ma.eai.ovo.TCommentaireGestOperPK</class>
<class>ma.eai.ovo.TGestionnaire</class>
<class>ma.eai.ovo.TGestionnaireOperation</class>
<class>ma.eai.ovo.TGestionnaireOperationPK</class>
<class>ma.eai.ovo.THistoriqueStatut</class>
<class>ma.eai.ovo.TOperation</class>
<class>ma.eai.ovo.TParamNatureOperation</class>
<class>ma.eai.ovo.TParamStatutOperation</class>
<class>ma.eai.ovo.TOperation</class>
<class>ma.eai.gsc.entities.GscAutorisation</class>
<class>ma.eai.gsc.entities.GscAutorisationSolde</class>
<class>ma.eai.gsc.entities.GscBlocage</class>
<class>ma.eai.gsc.entities.GscCreanceImpaye</class>
<class>ma.eai.gsc.entities.GscEvenement</class>
<class>ma.eai.gsc.entities.GscEvenementElementaire</class>
<class>ma.eai.gsc.entities.GscImpaye</class>
<class>ma.eai.gsc.entities.GscMotif</class>
<class>ma.eai.gsc.entities.GscOperation</class>
<class>ma.eai.gsc.entities.GscOpposition</class>
<class>ma.eai.gsc.entities.GscOppositionCheque</class>
<class>ma.eai.gsc.entities.GscOppositionLcn</class>
<class>ma.eai.gsc.entities.GscOppositionPrelevement</class>
<class>ma.eai.gsc.entities.GscProduit</class>
<class>ma.eai.gsc.entities.GscReleve</class>
<class>ma.eai.gsc.entities.GscRembCdl</class>
<class>ma.eai.gsc.entities.GscSolde</class>
<class>ma.eai.gsc.entities.GscSoldeForImpaye</class>
<class>ma.eai.gsc.entities.GscSoldeImpaye</class>
<class>ma.eai.gsc.entities.GscSop</class>
<class>ma.eai.gsc.entities.GscTestSold</class>
<class>ma.eai.gsc.entities.GscType</class>
<exclude-unlisted-classes/>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect" />
<property name="jdbc_url" value="jdbc:oracle:thin:@10.100.161.58:1521:bkoffice"/>
<property name="jdbc_driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="user_id" value="VIREMENT"/>
<property name="pswd" value="123456"/>
</properties>

</persistence-unit>

</persistence>
*************************************
can u please help me with that

email:s.daouiji@gmail.com