0 Replies Latest reply on Jun 10, 2011 7:44 AM by flopsi

    Unwanted update on entity

    flopsi
      Hi folks,
      i have a problem regarding a bidirectional many-to-many relationship as follows:

      In Entity One:
      @ManyToMany(fetch = FetchType.LAZY, cascade={CascadeType.PERSIST})
      @JoinTable(name = "pp_offer_content", catalog = "pportal_v5", joinColumns = { @JoinColumn(name = "offer_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "content_id", nullable = false, updatable = false) })
      public Set<PpContent> getPpContents() {
        return this.ppContents;
      }
      public void setPpContents(Set<PpContent> ppContents) {
        this.ppContents = ppContents;
      }

      In Entity Two (Back-Reference):
      @ManyToMany(fetch = FetchType.LAZY, mappedBy="ppContents")
      public Set<PpOffer> getPpOffers() {
        return this.ppOffers;
      }
      public void setPpOffers(Set<PpOffer> ppOffers) {
        this.ppOffers = ppOffers;
      }

      The problem is that when i try to do an update on entity two, hibernate also tries to do an update on entity one although we do not have a cascade attribute and even worse nothing is changed there (as i understand, the id remains so nothing to do for parent and join tables).
      The consequence is that i get an exception, cos some not-null values in entity one are not filled at that time.

      I wonder why hibernate tries to save object one apparently without e.g. having set a cascade attribute telling that...
      Any ideas on that?

      Thanks a lot, best regards
      Flo