Injecting Entity Manager automatically in JPA 2.0 -


i have strange problem jsf 2.1 project working on using ibm rational application developer websphere software version 9.1, , websphere application server version 8.5.5 have created dynamic jsf web project jsf version 2.1, , ejb project containing entities , ejbs, ejb version 3.1 , jpa 2, , have included cdi (content , dependency injection) facet both jpa , jsf projects.

the project i'm working on simple news module supposed perform add, search, update , delete operations on news items , authors.

everything works fine when manually set entity manager, when don't set entity manager manually , leave injected automatically, nullpointerexception whenever try access entity manager.

my code follows

my persistence.xml:

<?xml version="1.0" encoding="utf-8"?> <persistence version="2.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_2_0.xsd">     <persistence-unit name="newsprojectpersistence" transaction-type="jta">         <jta-data-source>jndi/newsproj</jta-data-source>         <class>model.user</class>         <class>model.address</class>         <class>model.author</class>         <class>model.newsitem</class>     </persistence-unit> </persistence> 

my controller.java class (the ejb)

i have 2 jsp pages, login.jsp , index.jsp

my login.jsp

my login.java (pagecode/managed bean)

my index.jsp

my index.java (pagecode/managed bean)

and exception is:

        [7/24/16 16:53:32:544 eet] 00000092 annotation    w com.ibm.ws.webcontainer.annotation.wasannotationhelper inject srve8042e: internal error caused reference context enables injection not initialized properly. [7/24/16 16:53:35:765 eet] 00000092 errorpagewrit e   exception occurred         javax.faces.el.evaluationexception: org.apache.jasper.el.jspelexception: /login.jsp(63,9) '#{pc_login.dobtnloginaction}' java.lang.nullpointerexception         @ javax.faces.component._methodexpressiontomethodbinding.invoke(_methodexpressiontomethodbinding.java:96)         @ org.apache.myfaces.application.actionlistenerimpl.processaction(actionlistenerimpl.java:100)         @ javax.faces.component.uicommand.broadcast(uicommand.java:120)         @ javax.faces.component.uiviewroot._broadcastall(uiviewroot.java:973)         @ javax.faces.component.uiviewroot.broadcastevents(uiviewroot.java:275)         @ javax.faces.component.uiviewroot._process(uiviewroot.java:1285)         @ javax.faces.component.uiviewroot.processapplication(uiviewroot.java:711)         @ org.apache.myfaces.lifecycle.invokeapplicationexecutor.execute(invokeapplicationexecutor.java:34)         @ org.apache.myfaces.lifecycle.lifecycleimpl.executephase(lifecycleimpl.java:172)         @ org.apache.myfaces.lifecycle.lifecycleimpl.execute(lifecycleimpl.java:119)         @ javax.faces.webapp.facesservlet.service(facesservlet.java:189)         @ com.ibm.ws.webcontainer.servlet.servletwrapper.service(servletwrapper.java:1227)         @ com.ibm.ws.webcontainer.servlet.servletwrapper.handlerequest(servletwrapper.java:776)         @ com.ibm.ws.webcontainer.servlet.servletwrapper.handlerequest(servletwrapper.java:458)         @ com.ibm.ws.webcontainer.servlet.servletwrapperimpl.handlerequest(servletwrapperimpl.java:178)         @ com.ibm.ws.webcontainer.filter.webappfiltermanager.invokefilters(webappfiltermanager.java:1032)         @ com.ibm.ws.webcontainer.servlet.cacheservletwrapper.handlerequest(cacheservletwrapper.java:87)         @ com.ibm.ws.webcontainer.webcontainer.handlerequest(webcontainer.java:909)         @ com.ibm.ws.webcontainer.wswebcontainer.handlerequest(wswebcontainer.java:1662)         @ com.ibm.ws.webcontainer.channel.wcchannellink.ready(wcchannellink.java:200)         @ com.ibm.ws.http.channel.inbound.impl.httpinboundlink.handlediscrimination(httpinboundlink.java:459)         @ com.ibm.ws.http.channel.inbound.impl.httpinboundlink.handlenewrequest(httpinboundlink.java:526)         @ com.ibm.ws.http.channel.inbound.impl.httpinboundlink.processrequest(httpinboundlink.java:312)         @ com.ibm.ws.http.channel.inbound.impl.httpiclreadcallback.complete(httpiclreadcallback.java:88)         @ com.ibm.ws.tcp.channel.impl.aioreadcompletionlistener.futurecompleted(aioreadcompletionlistener.java:175)         @ com.ibm.io.async.abstractasyncfuture.invokecallback(abstractasyncfuture.java:217)         @ com.ibm.io.async.asyncchannelfuture.firecompletionactions(asyncchannelfuture.java:161)         @ com.ibm.io.async.asyncfuture.completed(asyncfuture.java:138)         @ com.ibm.io.async.resulthandler.complete(resulthandler.java:204)         @ com.ibm.io.async.resulthandler.runeventprocessingloop(resulthandler.java:775)         @ com.ibm.io.async.resulthandler$2.run(resulthandler.java:905)         @ com.ibm.ws.util.threadpool$worker.run(threadpool.java:1862)     caused by: org.apache.jasper.el.jspelexception: /login.jsp(63,9) '#{pc_login.dobtnloginaction}' java.lang.nullpointerexception         @ org.apache.jasper.el.jspmethodexpression.invoke(jspmethodexpression.java:79)         @ javax.faces.component._methodexpressiontomethodbinding.invoke(_methodexpressiontomethodbinding.java:88)         ... 31 more     caused by: java.lang.nullpointerexception         @ beans.controller.checkauthentication(controller.java:157)         @ pagecode.login.dobtnloginaction(login.java:72)         @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)         @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:60)         @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:37)         @ java.lang.reflect.method.invoke(method.java:611)         @ org.apache.el.parser.astvalue.invoke(astvalue.java:268)         @ org.apache.el.methodexpressionimpl.invoke(methodexpressionimpl.java:278)         @ org.apache.jasper.el.jspmethodexpression.invoke(jspmethodexpression.java:70)         ... 32 more 

i have tried provide information can this, since have tried found online , asked lot , didn't work.

the exception because reference context enables injection not initialized properly, , have no idea why. far know, have done right appreciated

[edit]: such when use emf = persistence.createentitymanagerfactory("newsprojectpersistence"); , em = emf.createentitymanager(); (when set entity manager manually), runs fine, when remove these lines shown in controller.java nullpointerexception whenever try access entity manager.

also, understand, don't need call em.flush() in order reflect changes on database , changes should flushed automatically. however, not case here. when set entity manager manually , database operations working, need flush manually in order reflect changes on database. don't know whether has fact automatic injection isn't enabled.


Comments