-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Cannot delete 1:n association
PostPosted: Tue Nov 02, 2010 11:54 am 
Newbie

Joined: Thu Jul 15, 2010 5:06 am
Posts: 7
Hello!
I have a problem with deleting an 1:n association.
I have two objects which have a bidirectional 1:n association. Now I want to delete this association without deleting the objects. However this is not working. I want to delete the association between the dashboard and one medical document object.

These are my two xml mapping files:

1. Dashboard mapping:
Code:
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
   <class name="at.ac.uibk.dbis.dmis.server.application.findings.Dashboard" table="Dashboard">
      <id name="PID" column="PID" >
         <generator class="increment"/>
      </id>
      <set name="medicalDocuments" inverse="true" table="dashboard_medicalDocuments">
         <key column="dashboard_id"></key>
         <many-to-many class="at.ac.uibk.dbis.dmis.server.application.findings.MedicalDocument" column="medicalDocument_id" unique="true"></many-to-many>
      </set>    
   </class>
</hibernate-mapping>


2. MedicalDocuments mapping:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="at.ac.uibk.dbis.dmis.server.application.findings">
<class name="MedicalDocument" table="MedicalDocument" lazy="false">
      <id name="PID" column="PID" >
         <generator class="increment"/>
      </id>
      <property name="requestDate" column="RequestDate" />
      <property name="receiptDate" column="ReceiptDate" />
      <property name="docID" column="DocID" />
      <property name="labID" column="LabID" />
      <property name="loincName" column="LoincName" />
      <property name="loincCode" column="LoincCode" />
      <property name="title" column="Title" />
      <property name="xmlFile" column="XMLFile" />
      <property name="avaiable" column="Avaiable" />
      <join table="patient_medicalDocuments">
         <key column="medicalDocument_id"></key>
         <many-to-one name="patient" class="at.ac.uibk.dbis.dmis.server.application.patient.Patient">
            <column name="patient_id" not-null="true"></column>
         </many-to-one>
      </join>
      <join table="dmissession_medicaldocuments">
         <key column="medicalDocument_id"></key>
         <many-to-one name="session" class="at.ac.uibk.dbis.dmis.server.application.session.DmisSession">
            <column name="dmissession_id" not-null="true"></column>
         </many-to-one>
      </join>
      <join table="dashboard_medicalDocuments">
         <key column="medicalDocument_id"></key>
         <many-to-one name="dashboard" class="at.ac.uibk.dbis.dmis.server.application.findings.Dashboard" cascade="all">
            <column name="dashboard_id" not-null="true"></column>
         </many-to-one>
      </join>
   </class>
</hibernate-mapping>


This is my Dashboard method:
Code:
public void removeMedicalDocument(MedicalDocument doc){
      log.debug("Loading the medical document from the database...");
      log.debug("Current number of medical documents on this dashboard:"+this.getMedicalDocuments().size());
      
      List<MedicalDocument> docs = new ArrayList<MedicalDocument>(this.getMedicalDocuments());
      for(int i = 0; i< docs.size(); i++){
         if(docs.get(i).getPID() == doc.getPID()){
            this.getMedicalDocuments().remove(docs.get(i));
         }
      }
      log.debug("Updating now the database...");
      this.updateDashboard();
      log.debug("Update finished...");
      
      log.debug("Current number of medical documents on this dashboard:"+this.getMedicalDocuments().size());
   }

public void updateDashboard(){
      DashboardHibernate.updateDashboard(this);
   }


And this is my hibernate file where a make the update:
Code:
public static DmisSession updateDmisSession(DmisSession dmisSession){
      try {
         Session session = SessionFactoryUtil.getInstance().getCurrentSession();
         Transaction tx = session.beginTransaction();
      
         session.update(dmisSession);
         
         tx.commit();
         return dmisSession;
      }
      catch(RuntimeException e){
         try {
            Session session = SessionFactoryUtil.getInstance().getCurrentSession();
            if(session.getTransaction().isActive())
               session.getTransaction().rollback();
         }
         catch (HibernateException e1){
            log.error("Error rolling back transaction");
         }
         throw e;
      }
   }


What am I doing worng thet the association is not deleted?

Thanks,
Florian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.