-->
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.  [ 3 posts ] 
Author Message
 Post subject: Cascading delete question - short version
PostPosted: Wed Mar 22, 2006 7:57 pm 
Beginner
Beginner

Joined: Fri Feb 24, 2006 1:18 pm
Posts: 25
Hey folks - I don't know if I the following is a feature of Hibernate (2.1.8) or a problem with my code/configuration.

The core of the issue are three objects - Camp, CampWeek, ChildrenInCampWeek (yes, a little Camp Reservation system for the kids). A Camp has many CampWeeks and each CampWeek can have many children in it.

When I delete the Camp, I am expecting that all the CampWeeks for that Camp should be deleted and that any ChildInCampWeeks for those CampWeeks should also be deleted.

When I have one child in a number of CampWeeks for Camp1, everything works as outlined above. However, when I have a second child in those same CampWeeks, then I get errors such as:
DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_ChildInCampWeek_CampWeek'. The conflict occurred in database 'Reservations', table 'ChildInCampWeek', column 'CampWeekId'.

Without getting too lengthy here, the Camp.hbm contains:
Code:
<set cascade="all-delete-orphan" inverse="true" name="CampWeekSet" sort="camp.CampWeek$CampWeekComparator">
   <key column="CampId" />
   <one-to-many class="CampWeek" />
</set>

CampWeek.hbm has:
Code:
<set
   cascade="all-delete-orphan"
   name="ChildInCampWeekSet"
   table="ChildInCampWeek"
   sort="camp.ChildInCampWeek$ChildInCampWeekComparator"
   inverse="true"         
>
   <key column="CampWeekId" />
   <one-to-many class="ChildInCampWeek" />
</set>

ChildInCampWeek.hbm has:
Code:
<many-to-one
   class="Child"
   name="Child"
   not-null="true"
>   
  <column name="ChildId" />
</many-to-one>
<many-to-one
   class="CampWeek"
   name="CampWeek"
   not-null="true"
>
  <column name="CampWeekId" />
</many-to-one>

my code is simply:
Code:
  public static void deleteCamp(Camp camp) throws HibernateException {
    Session session = getSession();
    Transaction tx = null;
    try {     
      tx = session.beginTransaction();
      session.delete(camp);
      tx.commit();
    } catch (HibernateException e) {
      System.out.println("Rolling back");
      if (tx != null) {
        tx.rollback();
      }
      e.printStackTrace();
    } finally {
      session.close();
    }
  }


Am I doing something wrong here? Thanks so much!!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 9:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Wrong forum

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 11:38 am 
Beginner
Beginner

Joined: Fri Feb 24, 2006 1:18 pm
Posts: 25
I realized that after I posted here - but I couldn't figure out how to delete it. Please feel free to remove this topic.
Thanks,
RB


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

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.