0 Replies Latest reply on Apr 17, 2003 8:28 AM by Michael Delamere

    m-n relationship

    Michael Delamere Newbie


      I have tried asking this in the cmp forum but unfortunately I got no reply. I am sorry if I am cross posting but I really do need some help on this.




      I am starting to go nuts with my n-m mapping :-). I've read various docs and
      have gone through the archive but I haven?t been able to get any wiser on
      this. Below you can see the code for adding ProfileValues to my relation
      profiles-collection in the CustomerValue. I then pass the CustomerValue to my
      sessionfacade which is supposed to handle the storing of my relationship
      customer<->profile. For some reason though the customer values are set
      correctly in the relationship table but the profile values have been newly
      created producing new values as apposed to writing the values that I passed
      to the session facade! If I then comment out the sequence key generation in
      my profile create method and just set the id form my profileValue object I
      get a "Entity with primary key [.139.] already exists" exception!?

      Could someone PLEASE help me on getting my relationship table filled with
      the correct values......

      I would be very grateful for any help given.



      customer_id | profile_id
      22 | 190 | new value instead of value
      22 | 191 | passed to sessionfacade
      22 | 192 | which is 139

      Client code: (processing form data)
      * Client code for creating new ProfileValues from form input
      * and adding to customer (relation) collection
      public static CustomerValue addProfiesToCustomer(String[] profiles,
      CustomerValue cv) {
      for (int i = 0; i < profiles.length; i++) {
      ProfileValue pv = new ProfileValue(new Integer(profiles), null,
      return cv;

      Profiles Sessionfacade code (storing to relation table)
      * Store the Customer-Profile relation in the relation table
      * using the values passed from the client code above
      public void storeCustomerProfiles(CustomerValue cv) {
      CustomerLocalHome home = null;

      try {
      home = (CustomerLocalHome) CustomerUtil.getLocalHome();
      CustomerLocal cl = home.findByPrimaryKey(new
      } catch(Exception e) {