i try delete 1 row in table:
my page:
<p:datatable id="table" styleclass="tablehistory" value="#{patientcardmb.history}" var="history" paginator="true" rows="15" rowkey="#{history.id}" selection="#{patientcardmb.patientcard}" selectionmode="single" > <f:facet name="header"> historia </f:facet> <p:column headertext="#{msg.date}"> <h:outputtext id="historytext" value="#{history.datevisit}"/> </p:column> <p:ajax event="rowselect" listener="#{tablebean.onrowselect()}" update=":form:table" /> <f:facet name="footer"> <p:commandbutton id="viewbutton" value="#{msg.info}" icon="ui-icon-search" update=":form:display" oncomplete="userdialog.show()" disabled="#{tablebean.flag}"/> <p:commandbutton action="#{patientcardmb.createstart()}" value="#{msg.add}" icon="ui-icon-plus" /> <p:commandbutton action="#{patientcardmb.editstart()}" value="#{msg.edit}" disabled="#{tablebean.flag}" ajax="false" icon="ui-icon-pencil"/> <p:commandbutton value="#{msg.delete}" onclick="confirmation.show()" type="button" disabled="#{tablebean.flag}" icon="ui-icon-close"/> <p:confirmdialog id="confirmdialog" message="jesteś pewien, że chcesz usunąć wybrany wpis?" header="potwierdzenie usunięcia" severity="alert" widgetvar="confirmation"> <p:commandbutton id="confirm" value="tak" oncomplete="confirmation.hide()" action="#{patientcardmb.delete()}" /> <p:commandbutton id="decline" value="nie" onclick="confirmation.hide()" type="button" /> </p:confirmdialog> </f:facet> </p:datatable>
i method patientcardmb.delete()
:
public string delete() { system.out.println(patientcard); try { patientcarddao.delete(patientcard); } catch (ejbexception e) { senderrormessagetouser("błąd usuwania wpisu"); } sendinfomessagetouser("wpis usunięty"); return "delete"; }
patientcarddao.delete:
@override public void delete(patientcard patientcard) { patientcard toremoved = em.merge(patientcard); em.remove(toremoved); }
entity patientcard:
public class patientcard implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.identity) @basic(optional = false) @column(name = "id") private integer id; @basic(optional = false) @notnull @column(name = "datevisit") @temporal(temporaltype.timestamp) private date datevisit; @size(max = 4000) @column(name = "diagnosis") private string diagnosis; @size(max = 250) @column(name = "medications") private string medications; @joincolumn(name = "patient_id", referencedcolumnname = "id") @manytoone(optional = false) private user patientid; @joincolumn(name = "doctor_id", referencedcolumnname = "id") @manytoone(optional = false) private user doctorid;
when try delete have error:
warning: dtx5014: caught exception in beforecompletion() callback: javax.persistence.entitynotfoundexception: deleted entity passed persist: [pl.eprzychodnia.model.patientcard#] @ org.hibernate.ejb.abstractentitymanagerimpl.throwpersistenceexception(abstractentitymanagerimpl.java:621) @ org.hibernate.ejb.abstractentitymanagerimpl$1.beforecompletion(abstractentitymanagerimpl.java:532) @ com.sun.enterprise.transaction.javaeetransactionimpl.commit(javaeetransactionimpl.java:435) @ com.sun.enterprise.transaction.javaeetransactionmanagersimplified.commit(javaeetransactionmanagersimplified.java:855) @ com.sun.ejb.containers.basecontainer.completenewtx(basecontainer.java:5136) @ com.sun.ejb.containers.basecontainer.postinvoketx(basecontainer.java:4901) @ com.sun.ejb.containers.basecontainer.postinvoke(basecontainer.java:2045) @ com.sun.ejb.containers.basecontainer.postinvoke(basecontainer.java:1994) @ com.sun.ejb.containers.ejblocalobjectinvocationhandler.invoke(ejblocalobjectinvocationhandler.java:222) @ com.sun.ejb.containers.ejblocalobjectinvocationhandlerdelegate.invoke(ejblocalobjectinvocationhandlerdelegate.java:89) @ com.sun.proxy.$proxy203.delete(unknown source) @ pl.eprzychodnia.mb.patientcardmb.delete(patientcardmb.java:102) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ javax.el.beanelresolver.invokemethod(beanelresolver.java:779) @ javax.el.beanelresolver.invoke(beanelresolver.java:528) @ javax.el.compositeelresolver.invoke(compositeelresolver.java:257) @ com.sun.el.parser.astvalue.invoke(astvalue.java:248) @ com.sun.el.methodexpressionimpl.invoke(methodexpressionimpl.java:302) @ com.sun.faces.facelets.el.tagmethodexpression.invoke(tagmethodexpression.java:105) @ javax.faces.component.methodbindingmethodexpressionadapter.invoke(methodbindingmethodexpressionadapter.java:88) @ com.sun.faces.application.actionlistenerimpl.processaction(actionlistenerimpl.java:102) @ javax.faces.component.uicommand.broadcast(uicommand.java:315) @ javax.faces.component.uidata.broadcast(uidata.java:1093) @ javax.faces.component.uiviewroot.broadcastevents(uiviewroot.java:794) @ javax.faces.component.uiviewroot.processapplication(uiviewroot.java:1259) @ 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:118) @ javax.faces.webapp.facesservlet.service(facesservlet.java:593) @ org.apache.catalina.core.standardwrapper.service(standardwrapper.java:1550) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:281) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:175) @ org.apache.catalina.core.standardpipeline.doinvoke(standardpipeline.java:655) @ org.apache.catalina.core.standardpipeline.invoke(standardpipeline.java:595) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:161) @ org.apache.catalina.connector.coyoteadapter.doservice(coyoteadapter.java:331) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:231) @ com.sun.enterprise.v3.services.impl.containermapper$adaptercallable.call(containermapper.java:317) @ com.sun.enterprise.v3.services.impl.containermapper.service(containermapper.java:195) @ com.sun.grizzly.http.processortask.invokeadapter(processortask.java:860) @ com.sun.grizzly.http.processortask.doprocess(processortask.java:757) @ com.sun.grizzly.http.processortask.process(processortask.java:1056) @ com.sun.grizzly.http.defaultprotocolfilter.execute(defaultprotocolfilter.java:229) @ com.sun.grizzly.defaultprotocolchain.executeprotocolfilter(defaultprotocolchain.java:137) @ com.sun.grizzly.defaultprotocolchain.execute(defaultprotocolchain.java:104) @ com.sun.grizzly.defaultprotocolchain.execute(defaultprotocolchain.java:90) @ com.sun.grizzly.http.httpprotocolchain.execute(httpprotocolchain.java:79) @ com.sun.grizzly.protocolchaincontexttask.docall(protocolchaincontexttask.java:54) @ com.sun.grizzly.selectionkeycontexttask.call(selectionkeycontexttask.java:59) @ com.sun.grizzly.contexttask.run(contexttask.java:71) @ com.sun.grizzly.util.abstractthreadpool$worker.dowork(abstractthreadpool.java:532) @ com.sun.grizzly.util.abstractthreadpool$worker.run(abstractthreadpool.java:513) @ java.lang.thread.run(thread.java:722)
warning: ejb5184:a system exception occurred during invocation on ejb patientcarddao, method: public void pl.eprzychodnia.dao.patientcarddao.delete(pl.eprzychodnia.model.patientcard) warning: javax.ejb.ejbexception: transaction aborted @ com.sun.ejb.containers.basecontainer.completenewtx(basecontainer.java:5142) @ com.sun.ejb.containers.basecontainer.postinvoketx(basecontainer.java:4901) @ com.sun.ejb.containers.basecontainer.postinvoke(basecontainer.java:2045) @ com.sun.ejb.containers.basecontainer.postinvoke(basecontainer.java:1994) @ com.sun.ejb.containers.ejblocalobjectinvocationhandler.invoke(ejblocalobjectinvocationhandler.java:222) @ com.sun.ejb.containers.ejblocalobjectinvocationhandlerdelegate.invoke(ejblocalobjectinvocationhandlerdelegate.java:89) @ com.sun.proxy.$proxy203.delete(unknown source) @ pl.eprzychodnia.mb.patientcardmb.delete(patientcardmb.java:102) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ javax.el.beanelresolver.invokemethod(beanelresolver.java:779) @ javax.el.beanelresolver.invoke(beanelresolver.java:528) @ javax.el.compositeelresolver.invoke(compositeelresolver.java:257) @ com.sun.el.parser.astvalue.invoke(astvalue.java:248) @ com.sun.el.methodexpressionimpl.invoke(methodexpressionimpl.java:302) @ com.sun.faces.facelets.el.tagmethodexpression.invoke(tagmethodexpression.java:105) @ javax.faces.component.methodbindingmethodexpressionadapter.invoke(methodbindingmethodexpressionadapter.java:88) @ com.sun.faces.application.actionlistenerimpl.processaction(actionlistenerimpl.java:102) @ javax.faces.component.uicommand.broadcast(uicommand.java:315) @ javax.faces.component.uidata.broadcast(uidata.java:1093) @ javax.faces.component.uiviewroot.broadcastevents(uiviewroot.java:794) @ javax.faces.component.uiviewroot.processapplication(uiviewroot.java:1259) @ 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:118) @ javax.faces.webapp.facesservlet.service(facesservlet.java:593) @ org.apache.catalina.core.standardwrapper.service(standardwrapper.java:1550) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:281) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:175) @ org.apache.catalina.core.standardpipeline.doinvoke(standardpipeline.java:655) @ org.apache.catalina.core.standardpipeline.invoke(standardpipeline.java:595) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:161) @ org.apache.catalina.connector.coyoteadapter.doservice(coyoteadapter.java:331) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:231) @ com.sun.enterprise.v3.services.impl.containermapper$adaptercallable.call(containermapper.java:317) @ com.sun.enterprise.v3.services.impl.containermapper.service(containermapper.java:195) @ com.sun.grizzly.http.processortask.invokeadapter(processortask.java:860) @ com.sun.grizzly.http.processortask.doprocess(processortask.java:757) @ com.sun.grizzly.http.processortask.process(processortask.java:1056) @ com.sun.grizzly.http.defaultprotocolfilter.execute(defaultprotocolfilter.java:229) @ com.sun.grizzly.defaultprotocolchain.executeprotocolfilter(defaultprotocolchain.java:137) @ com.sun.grizzly.defaultprotocolchain.execute(defaultprotocolchain.java:104) @ com.sun.grizzly.defaultprotocolchain.execute(defaultprotocolchain.java:90) @ com.sun.grizzly.http.httpprotocolchain.execute(httpprotocolchain.java:79) @ com.sun.grizzly.protocolchaincontexttask.docall(protocolchaincontexttask.java:54) @ com.sun.grizzly.selectionkeycontexttask.call(selectionkeycontexttask.java:59) @ com.sun.grizzly.contexttask.run(contexttask.java:71) @ com.sun.grizzly.util.abstractthreadpool$worker.dowork(abstractthreadpool.java:532) @ com.sun.grizzly.util.abstractthreadpool$worker.run(abstractthreadpool.java:513) @ java.lang.thread.run(thread.java:722) caused by: javax.transaction.rollbackexception: transaction marked rollback. @ com.sun.enterprise.transaction.javaeetransactionimpl.commit(javaeetransactionimpl.java:473) @ com.sun.enterprise.transaction.javaeetransactionmanagersimplified.commit(javaeetransactionmanagersimplified.java:855) @ com.sun.ejb.containers.basecontainer.completenewtx(basecontainer.java:5136) ... 51 more caused by: javax.persistence.entitynotfoundexception: deleted entity passed persist: [pl.eprzychodnia.model.patientcard#] @ org.hibernate.ejb.abstractentitymanagerimpl.throwpersistenceexception(abstractentitymanagerimpl.java:621) @ org.hibernate.ejb.abstractentitymanagerimpl$1.beforecompletion(abstractentitymanagerimpl.java:532) @ com.sun.enterprise.transaction.javaeetransactionimpl.commit(javaeetransactionimpl.java:435) ... 53 more
i don't why have error. earlier did delete similar entity, , work.
i think you're missing process , update attribute in
<p:commandbutton id="confirm" value="tak" oncomplete="confirmation.hide()" action="#{patientcardmb.delete()}" process="@parent" update="@form" />
Comments
Post a Comment