-->
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: Relation many-to-one + cascade="delete"
PostPosted: Thu Jan 27, 2005 10:16 am 
Newbie

Joined: Sun Aug 29, 2004 3:31 pm
Posts: 8
I have 2 classes Town -*---------1-> Country
Code:
public class Town extends BaseObject implements Serializable {
   protected String name;
   protected Country country;
   /**
    * @hibernate.many-to-one
    *       column="FK_COUNTRY_ID"
    *       class="org.appfuse.model.Country"
    *       cascade="delete"
    */
   public Country getCountry() {
      return country;
   }
   // other getters and setters
}

and
Code:
public class Country extends BaseObject implements Serializable {
   protected String code;
   protected String name;
   // getters and setters
}


When I delete any Town it is cascaded to Country - what I need is to be it cascaded inversly - to not generate unconsitency but remove unconsitency.

Inverse tag doesn exists in relationship many-to-one :(

Thanks in advance.[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 10:51 am 
Newbie

Joined: Sun Aug 29, 2004 3:31 pm
Posts: 8
hibernate-2.1.7

MySQL4.0.22-log

Generated Hibernate mappings:
Town:
Code:
   <class
        name="org.appfuse.model.Town"
        table="town"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >
        <id
            name="postalCode"
            column="postal_code"
            type="java.lang.String"
        >
            <generator class="assigned">
            </generator>
        </id>

        <many-to-one
            name="country"
            class="org.appfuse.model.Country"
            cascade="delete"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            column="FK_COUNTRY_ID"
            unique="false"
        />

        <property
            name="name_i18n"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="name"
            not-null="true"
        />

    </class>


Country:
Code:
   <class
        name="org.appfuse.model.Country"
        table="country"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >

        <id
            name="code"
            column="code"
            type="java.lang.String"
            length="4"
        >
            <generator class="assigned">
            </generator>
        </id>

        <property
            name="name_i18n"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="name"
            not-null="true"
        />
        <bag
            name="towns"
            lazy="true"
            inverse="true"
            cascade="save-update"
        >
              <key
                  column="FK_COUNTRY_ID"
              >
              </key>

              <one-to-many
                  class="org.appfuse.model.Town"
              />

        </bag>
    </class>



Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 11:37 am 
Newbie

Joined: Sun Aug 29, 2004 3:31 pm
Posts: 8
If anyone is solving the same problem:
Code:

public class Country extends BaseObject implements Serializable {
   protected String code;
   protected String name;
   protected Map towns;
   /**
    * @return
    * @hibernate.bag
    *       name="towns"
    *       cascade="delete" lazy="true"
    *      inverse="true"
    *
    * @hibernate.collection-key column="FK_COUNTRY_ID"
    * @hibernate.collection-one-to-many class="org.appfuse.model.Town"
    */
   public List getTowns() {
      return towns;
   }

   // getters and setters
}


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.