0 Replies Latest reply on Sep 18, 2008 4:28 PM by chris wang

    How to turn off cascading saving/deleting

    chris wang Newbie

      I have a SITE, and a SHIPTYPE table. These two table have a many-to-may relationship (the cross reference table is SHIPTYPE_X_SITE). I created the corresponding entities Site and ShipType. For the creation of ShipType, my UI has ShipType related fields as well as a list of sites. Therefore,ShipType has a collection of Sites:

      @ManyToMany(fetch=FetchType.LAZY)
      @JoinTable(name="SHIPTYPE_X_SITE",
      joinColumns={@JoinColumn(name="SHIP_TYPE_CD",referencedColumnName="SHIP_TYP_CD")},
      inverseJoinColumns={@JoinColumn(name="ST_SITE_ID",referencedColumnName="SITE_ID")})
      private List sites;

      and the cross reference records are saved when I save ShipType. That is good.

      On the other side, the creation of Site just have some basic Site related fields. There is no list of ShipTYPES in the UI.

      However, I do have the need to retrieve list of ShipTypes associated with a site sometimes. So I added following association to Site entity bean:

      @ManyToMany(fetch=FetchType.LAZY)
      @JoinTable(name="SHIPTYPE_X_SITE",
      joinColumns={@JoinColumn(name="ST_SITE_ID",referencedColumnName="SITE_ID")},
      inverseJoinColumns={@JoinColumn(name="SHIP_TYPE_CD",referencedColumnName="SHIP_TYP_CD")})
      private List shipTypes;

      Once I did that, if I modify Site and save (collection shipTypes is null), all the cross reference records are gone for the given site. My question is how can I make the Site bean has the association, but not doing the cascading? Thank you very much for you help.