2 Replies Latest reply on Nov 15, 2004 1:58 PM by jaime

    Insertin records on One-to-Many relation

    jaime

      Hi

      I have some problema

      I have master-detail relationship (one-to-many):a user has a list of roles. I try to insert a record in the user table that contains the collection of ROLES to be inserted in the roles tables but when I execute the home.create only the master (user) table are updated and the detail table don't contains any record belong to the user that I insert.

      I'm using EJB2 with an CMR defined between the thwo EJB

      Somebody can tell me how I can insert the master and details records in one call to the Facade Session Bean??

      thanks for all

      JaimeS

        • 1. Re: Insertin records on One-to-Many relation
          jobor

          You have to use the cmr field of the user that is created. After creation you can have an empty Collection on calling the getCMRfield() method. Then you can use the Collection methods to add related CMP's to that collection.
          Suppose you hava an collection of roles(CMP's) in a Collection newRoles.

          user.getRoles.addAll(newRoles);

          This is just one way. Read the EJB spec for more.

          Johan

          • 2. Re: Insertin records on One-to-Many relation
            jaime

            Thanks for your reply

            I'm gona to read the EJB Spec

            thanks again