salut pour tout le monde :
j'ai un classe Document qui contient deux Collection :Collection lignesDocument; Collection paiementDocument.
-mapping de Document :Code:
<class name="ClassesJava.Document" table="DOCUMENT">
...
<set cascade="all,delete-orphan" name="lignesDocument" order-by="NUMERO_LIGNE" table="LIGNE_COMMANDE">
<key>
<column name="NUMERO_PIECE"/>
<column name="DOCUMENT_TYPE"/>
</key>
<one-to-many class="ClassesJava.LigneDocument"/>
</set>
<set cascade="all,delete-orphan" name="paiementDocument" table="PAIEMENT_DOCUMENT">
<key>
<column name="NUMERO_PIECE"/>
<column name="DOCUMENT_TYPE"/>
</key>
<one-to-many class="ClassesJava.PaiementDocument"/>
</set>
..
</class>
-mapping de lignesDocument:Code:
<class name="ClassesJava.LigneDocument" table="LIGNE_DOCUMENT">
...
<many-to-one class="ClassesJava.Document" name="document">
<column name="NUMERO_PIECE"/>
<column name="DOCUMENT_TYPE"/>
</many-to-one>
</class>
-mapping de paiementDocument:Code:
<class name="ClassesJava.PaiementDocument" table="PAIEMENT_DOCUMENT" lazy="false">
...
<many-to-one class="ClassesJava.Document" insert="false" name="document" update="false">
<column name="NUMERO_PIECE"/>
<column name="DOCUMENT_TYPE"/>
</many-to-one>
</class>
si je veux supprimer un document il doit supprimer les lignes de document et les paiement associés a ce document : ca marche avec les lignes de document mais il ne supprime pas les paiements et m'affiche l'erreur suivante :
Code:
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [ClassesJava.PaiementDocument#ClassesJava.PaiementDocument@ae8f9c]
at org.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:1014)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:165)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:218)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at gestioncommerciale.Commande_Client.supprimerDocument(Commande_Client.java:2430)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
at com.sun.rave.web.ui.appbase.faces.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
at javax.faces.component.UICommand.broadcast(UICommand.java:383)
at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.execute(PartialTraversalLifecycle.java:94)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
la fonction de suppression et la suivante (je croit que c'est correcte car si je supprime un document qui ne contient pas des paiement ca marche bien )
Code:
public void supprimerDocument() {
if (document.getIdentifiant() != null && !docGenererParCopie && modificationdoc) {
ServiceBean service = (ServiceBean) ServiceFinder.getBean("#{ServiceBean}", ServiceBean.class);
Session sess = service.getTheSession();
try {
IdDocument id = document.getIdentifiant();
sess.beginTransaction();
Document doc = (Document) sess.load(Document.class, id);
sess.delete(doc);
sess.getTransaction().commit();
sess.flush();
message = "Le document : " + id.toString() + " est supprimé";
showPanelGroupe = true;
reinitialiserDocument();
} catch (Exception e) {
e.printStackTrace();
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage msg = new FacesMessage();
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
msg.setSummary("Le document n'est pas supprimer : " + e.getMessage());
context.addMessage(null, msg);
showPanelGroupe = true;
}
} else if (!modificationdoc) {
reinitialiserDocument();
message = "Veuillez charger un document pour le supprimé";
}
}
j'ai essai pas mal de fois avec ce code mais ca marche pas .
j'ai vraiment besaoin de vos aide et merci pour tout le monde .