2 Replies Latest reply on Oct 30, 2007 4:45 AM by mortena

    OneToMany - view

    mortena

      I've just started using Seam and needs to implement the following scenarios as one of the first:

      Entities:
      Person - has(1-*) Address.

      implemented it's something like:

      public class Person{

      @OneToMany
      List addresses;

      }

      I would like to be able to:


      Create a new Person with a default address in one form.
      Add new addresses to an existing Person.


      How do I do that?

      Can seam-gen handle relationships between entities?

        • 1. Re: OneToMany - view
          pmuir

           

          "mortena" wrote:
          Create a new Person with a default address in one form.
          Add new addresses to an existing Person.

          How do I do that?


          You probably want to extend the createInstance() method of PersonHome generated by seam-gen to add the default address to the person.

          @Override
          protected Person createInstance() {
           Person person = new Person();
           Address address = // lookup default address
           person.getAddresses().add(address);
           return person;
          }


          Though I would normally make address an embedded entity.

          Can seam-gen handle relationships between entities?


          Yes

          • 2. Re: OneToMany - view
            mortena

            One Person can have many addresses.

            Morten