java - javax.faces.el.EvaluationException: org.hibernate.LazyInitializationException: could not initialize proxy - no Session -
i'm working on project using jsf,spring , hibernate. exception in 1 case, don't understand reason why i'm getting problem. can give me idea did wrong
javax.el.elexception: /views/emissionsa.xhtml @102,171 actionlistener="#{emission1bean.payer()}": org.hibernate.lazyinitializationexception: not initialize proxy - no session @ com.sun.faces.facelets.el.tagmethodexpression.invoke(tagmethodexpression.java:111) @ javax.faces.event.methodexpressionactionlistener.processaction(methodexpressionactionlistener.java:147) eeeeeeeeeeeee @ javax.faces.event.actionevent.processlistener(actionevent.java:88) @ javax.faces.component.uicomponentbase.broadcast(uicomponentbase.java:813) @ javax.faces.component.uicommand.broadcast(uicommand.java:300) @ javax.faces.component.uiviewroot.broadcastevents(uiviewroot.java:790) @ javax.faces.component.uiviewroot.processapplication(uiviewroot.java:1282) @ com.sun.faces.lifecycle.invokeapplicationphase.execute(invokeapplicationphase.java:81) @ com.sun.faces.lifecycle.phase.dophase(phase.java:101) @ com.sun.faces.lifecycle.lifecycleimpl.execute(lifecycleimpl.java:198) @ javax.faces.webapp.facesservlet.service(facesservlet.java:646) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:301) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.netbeans.modules.web.monitor.server.monitorfilter.dofilter(monitorfilter.java:393) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:219) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:503) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:136) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:74) @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:610) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:516) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1015) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:652) @ org.apache.coyote.http11.http11nioprotocol$http11connectionhandler.process(http11nioprotocol.java:222) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1575) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1533) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745) caused by: org.hibernate.lazyinitializationexception: not initialize proxy - no session @ org.hibernate.proxy.abstractlazyinitializer.initialize(abstractlazyinitializer.java:164) @ org.hibernate.proxy.abstractlazyinitializer.getimplementation(abstractlazyinitializer.java:285) @ org.hibernate.proxy.pojo.javassist.javassistlazyinitializer.invoke(javassistlazyinitializer.java:185) @ net.vo.salaire_$$_javassist_5.getpersonnel(salaire_$$_javassist_5.java) @ controller.emission1bean.payer(emission1bean.java:58) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:483) @ org.apache.el.parser.astvalue.invoke(astvalue.java:261) @ org.apache.el.methodexpressionimpl.invoke(methodexpressionimpl.java:277) @ com.sun.faces.facelets.el.tagmethodexpression.invoke(tagmethodexpression.java:105) ... 34 more 25-jun-2014 23:42:28.209 severe [http-nio-8084-exec-134] com.sun.faces.context.ajaxexceptionhandlerimpl.handlepartialresponseerror org.hibernate.lazyinitializationexception: not initialize proxy - no session @ org.hibernate.proxy.abstractlazyinitializer.initialize(abstractlazyinitializer.java:164) @ org.hibernate.proxy.abstractlazyinitializer.getimplementation(abstractlazyinitializer.java:285) @ org.hibernate.proxy.pojo.javassist.javassistlazyinitializer.invoke(javassistlazyinitializer.java:185) @ net.vo.salaire_$$_javassist_5.getpersonnel(salaire_$$_javassist_5.java) @ controller.emission1bean.payer(emission1bean.java:58) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:483) @ org.apache.el.parser.astvalue.invoke(astvalue.java:261) @ org.apache.el.methodexpressionimpl.invoke(methodexpressionimpl.java:277) @ com.sun.faces.facelets.el.tagmethodexpression.invoke(tagmethodexpression.java:105) @ javax.faces.event.methodexpressionactionlistener.processaction(methodexpressionactionlistener.java:147) @ javax.faces.event.actionevent.processlistener(actionevent.java:88) @ javax.faces.component.uicomponentbase.broadcast(uicomponentbase.java:813) @ javax.faces.component.uicommand.broadcast(uicommand.java:300) @ javax.faces.component.uiviewroot.broadcastevents(uiviewroot.java:790) @ javax.faces.component.uiviewroot.processapplication(uiviewroot.java:1282) @ com.sun.faces.lifecycle.invokeapplicationphase.execute(invokeapplicationphase.java:81) @ com.sun.faces.lifecycle.phase.dophase(phase.java:101) @ com.sun.faces.lifecycle.lifecycleimpl.execute(lifecycleimpl.java:198) @ javax.faces.webapp.facesservlet.service(facesservlet.java:646) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:301) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.netbeans.modules.web.monitor.server.monitorfilter.dofilter(monitorfilter.java:393) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:219) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:503) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:136) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:74) @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:610) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:516) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1015) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:652) @ org.apache.coyote.http11.http11nioprotocol$http11connectionhandler.process(http11nioprotocol.java:222) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1575) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1533) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745)
emissionsa.xhtml
<?xml version='1.0' encoding='utf-8' ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> <h:head> <title>facelet title</title> <style> .p tr,.p td { border : none; } </style> </h:head> <h:body style="background-color: #ecf3fd;"> <h:graphicimage value="../../images/header.jpg" style="margin-left: auto;margin-right: auto;"></h:graphicimage> <ui:include src="menu.xhtml" /> <br/> <br/> <h:form id="form"> <p:datatable id="display" var="listeemissions" value="#{emission1bean.listeemissions}" editable="true" style="margin-bottom:10px" rowkey="#{listeemissions.dateemission}" selection="#{emission1bean.emission}" selectionmode="single"> <f:facet name="header"> liste des factures émises </f:facet> <p:ajax event="rowedit" listener="#{dteditview.onrowedit}" /> <p:ajax event="roweditcancel" listener="#{dteditview.onrowcancel}"/> <p:column headertext="date emission"> <p:celleditor> <f:facet name="output"><h:outputtext value="#{listeemissions.dateemission}" /></f:facet> <f:facet name="input"><p:inputtext id="modelinput" value="#{listeemissions.dateemission}" style="width:100%"/></f:facet> </p:celleditor> </p:column> <p:column headertext="n° ordre de paiement"> <p:celleditor> <f:facet name="output"><h:outputtext value="#{listeemissions.nop}" /></f:facet> <f:facet name="input"><p:inputtext value="#{listeemissions.nop}" style="width:100%" label="year"/></f:facet> </p:celleditor> </p:column> <p:column headertext="n° bordereau"> <p:celleditor> <f:facet name="output"><h:outputtext value="#{listeemissions.nbordereau}" /></f:facet> <f:facet name="input"><p:inputtext value="#{listeemissions.nbordereau}" style="width:100%" label="year"/></f:facet> </p:celleditor> </p:column> <p:column style="width:32px" headertext="modifier"> <p:commandlink styleclass="ui-icon ui-icon-pencil"/> </p:column> <p:column style="width:32px" headertext="supprimer"> <p:commandlink styleclass="ui-icon ui-icon-trash" action="#{emission1bean.delete()}" process="@this" update=":form:display"> <f:setpropertyactionlistener target="#{emission1bean.emission}" value="#{listeemissions}" /> </p:commandlink> </p:column> </p:datatable> <p:commandbutton value="payer le salaire" update="emissiondetail" oncomplete="pf('emissiondialog').show()" /> <p:dialog header="paiement du salaire" widgetvar="emissiondialog" modal="true" showeffect="fade" hideeffect="fade" resizable="false"> <p:panel id="emissiondetail" style="border:none;"> <p:panelgrid columns="2" rendered="#{not empty emission1bean.emission}" columnclasses="label,value" style="border:none;"> <p:accordionpanel> <p:tab title="payer le salaire"> <h:panelgrid styleclass="p" columns="2" cellpadding="5"> <h:outputtext value="date paiement: " /> <p:inputtext value="#{emission1bean.datepaiement}"/> <h:outputtext value="compte bancaire: " /> <p:selectonemenu value="#{comptebancairebean.idcompte}" > <f:selectitem itemvalue="#{null}" itemlabel="--séléctionner un fournisseur" /> <f:selectitems value="#{comptebancairebean.listecomptebancaires}" var="compte" itemvalue="#{compte.idcompte}" itemlabel="#{compte.libellecompte}" /> <f:ajax listener="#{comptebancairebean.submit()}"/> </p:selectonemenu> <h:outputtext value="n° chèque: " /> <p:inputtext value="#{emission1bean.ncheque}"/> <h:outputtext value="n° virement: " /> <p:inputtext value="#{emission1bean.nvirement}"/> <h:outputtext value="n° avis de virement: " /> <p:inputtext value="#{emission1bean.navis}"/> </h:panelgrid> </p:tab> </p:accordionpanel> </p:panelgrid> <p:commandbutton value="valider" icon="ui-icon-circle-check" update="display" onclick="emissiondialog.hide();" actionlistener="#{emission1bean.payer()}"/> <p:commandbutton value="annuler" icon="ui-icon-arrowreturnthick-1-w" onclick="emissiondialog.hide();"/> </p:panel> </p:dialog> </h:form> </h:body> </html>
emission1bean.java
@component @scope("view") public class emission1bean { @autowired private salairemetier salairemetier; @autowired private emissionmetier emissionmetier; @autowired private paiementmetier paiementmetier; @autowired private facturemetier facturemetier; @autowired private comptebancairemetier comptebancairemetier; private list<emission> listeemissions; private emission emission; private string dateemission; private salaire salaire; private integer nop; private integer nbordereau; private int idcompte; private string datepaiement; private comptebancaire comptebancaire; private archive archive; private integer ncheque; private integer nvirement; private integer navis; @postconstruct public void init() { listeemissions = emissionmetier.getallemissionssa(); } public void payer() { emission e = emissionmetier.getemission(getemission().getdateemission()); salaireid id = new salaireid(e.getsalaire().getpersonnel().getcin(),e.getsalaire().getmois().getmois()); salaire s = salairemetier.getsalaire(id); paiement p = new paiement(); p.setdatepaiement(getdatepaiement()); p.setsalaire(s); int c = comptebancairebean.submit(); comptebancaire compte = comptebancairemetier.getcomptebancaire(c); p.setcomptebancaire(compte); p.setnavis(getnavis()); p.setncheque(getncheque()); p.setnvirement(getnvirement()); paiementmetier.insert(p); } public int submit() { system.out.println(idcompte); return idcompte; } public void delete(){ emission e = emissionmetier.getemission(getemission().getdateemission()); emissionmetier.delete(getemission().getdateemission()); listeemissions.remove(emission); emission = null; salaireid id1 = new salaireid(e.getsalaire().getpersonnel().getcin(),e.getsalaire().getmois().getmois()); salaire sa = salairemetier.getsalaire(id1); sa.setetatsalaire("engage"); salairemetier.update(sa); } public salaire getsalaire() { return salaire; } public void setsalaire(salaire salaire) { this.salaire = salaire; } public comptebancairemetier getcomptebancairemetier() { return comptebancairemetier; } public void setcomptebancairemetier(comptebancairemetier comptebancairemetier) { this.comptebancairemetier = comptebancairemetier; } public paiementmetier getpaiementmetier() { return paiementmetier; } public void setpaiementmetier(paiementmetier paiementmetier) { this.paiementmetier = paiementmetier; } public facturemetier getfacturemetier() { return facturemetier; } public void setfacturemetier(facturemetier facturemetier) { this.facturemetier = facturemetier; } public int getidcompte() { return idcompte; } public void setidcompte(int idcompte) { this.idcompte = idcompte; } public string getdatepaiement() { return datepaiement; } public void setdatepaiement(string datepaiement) { this.datepaiement = datepaiement; } public comptebancaire getcomptebancaire() { return comptebancaire; } public void setcomptebancaire(comptebancaire comptebancaire) { this.comptebancaire = comptebancaire; } public archive getarchive() { return archive; } public void setarchive(archive archive) { this.archive = archive; } public integer getncheque() { return ncheque; } public void setncheque(integer ncheque) { this.ncheque = ncheque; } public integer getnvirement() { return nvirement; } public void setnvirement(integer nvirement) { this.nvirement = nvirement; } public integer getnavis() { return navis; } public void setnavis(integer navis) { this.navis = navis; } public emission getemission() { return emission; } public void setemission(emission emission) { this.emission = emission; } public list<emission> getlisteemissions() { return listeemissions; } public void setlisteemissions(list<emission> listeemissions) { this.listeemissions = listeemissions; } public emissionmetier getemissionmetier() { return emissionmetier; } public void setemissionmetier(emissionmetier emissionmetier) { this.emissionmetier = emissionmetier; } public string getdateemission() { return dateemission; } public void setdateemission(string dateemission) { this.dateemission = dateemission; } public integer getnop() { return nop; } public void setnop(integer nop) { this.nop = nop; } public integer getnbordereau() { return nbordereau; } public void setnbordereau(integer nbordereau) { this.nbordereau = nbordereau; } }
i know problem because of line don't know fix it
salaireid id = new salaireid(e.getsalaire().getpersonnel().getcin(),e.getsalaire().getmois().getmois());
edit
emissiondao.java
package dao; import java.util.list; import net.vo.emission; public interface emissiondao { public list getallemissions(); public list getallemissionssa(integer id,integer m); public emission getemission(string date); public void insert(emission emission); public void update(emission emission); public void delete(string date); }
emissionhibernatedao package dao;
import java.util.list; import net.vo.emission; import org.hibernate.hibernateexception; import org.hibernate.query; import org.hibernate.session; import org.hibernate.transaction; import org.springframework.stereotype.repository; @repository public class emissionhibernatedao implements emissiondao{ private list<emission> listeemissions; private emission emission; public void init() { system.out.println("méthode d'initiation"); } /*@override public list<object> getallemissions() { session session=hibernateutil.getsession(); try { session.begintransaction(); query q = session.createquery("select f.idfacture,f.datefacture,f.montantfacture,f.etatfacture,e.dateemission,e.nop,e.nbordereau facture f,emission e e.facture = f.idfacture , f.etatfacture='émise'"); listeemissions = q.list(); return listeemissions; } catch(hibernateexception e) { throw e; } { session.close(); } }*/ @override public list getallemissions() { session session=hibernateutil.getsession(); try { session.begintransaction(); query q = session.createquery("from emission e left join fetch e.facture f f.etatfacture = 'emise'"); listeemissions = q.list(); return listeemissions; } catch(hibernateexception e) { throw e; } { session.close(); } } @override public list getallemissionssa(integer id,integer m) { session session=hibernateutil.getsession(); try { session.begintransaction(); query q = session.createquery("from emission e left join fetch e.salaire s left join fetch s.personnel left join fetch s.mois m m.annee.annee =:annee , m.mois =:mois , s.etatsalaire = 'emis' "); q.setparameter("mois", m); q.setparameter("annee",id); listeemissions = q.list(); return listeemissions; } catch(hibernateexception e) { throw e; } { session.close(); } } @override public emission getemission(string date) { session session = hibernateutil.getsession(); try { system.out.println("eeeeeeeeeeeee"); session.begintransaction(); query q = session.createquery("from emission em em.dateemission='" + date +"'"); return (emission) q.uniqueresult(); } { session.close(); } } @override public void insert(emission emission) { session session = hibernateutil.getsession(); transaction tx=null; try { tx = session.begintransaction(); session.save(emission); tx.commit(); } catch(runtimeexception e) { if(tx != null) { tx.rollback(); } throw e; } { session.close(); } } @override public void update(emission emission) { session session = hibernateutil.getsession(); transaction tx=null; try { tx=session.begintransaction(); session.update(emission); tx.commit(); } catch(runtimeexception e) { if(tx != null) { tx.rollback(); } throw e; } { session.close(); } } @override public void delete(string date) { session session = hibernateutil.getsession(); transaction tx = null; try { tx=session.begintransaction(); emission = (emission) session.get(emission.class,date); session.delete(emission); tx.commit(); } catch(runtimeexception e) { if(tx != null) { tx.rollback(); } throw e; } { session.close(); } } }
this hibernate problem. entity has fields declared lazy loaded entity not attached valid hibernate session fire proxies retrieve data lazily. stacktrace, cannot sure if error thrown e.getsalaire().getpersonnel().getcin()
or .getsalaire().getmois().getmois()
(or maybe both).
i don't know how configured session management, spring handling it. solve this, should re attach entity valid hibernate session. can using hibernatetemplate#refresh
method spring hibernate integration classes.
Comments
Post a Comment