1 Reply Latest reply on Jul 26, 2006 8:13 AM by Pete Muir

    More seam examples

    krypton Novice

      Would it be possible to add more seam examples as I am having difficulty in developing a full blown application using seam. I posted this thread as i was having issues http://www.jboss.com/index.html?module=bb&op=viewtopic&t=87408
      with managing relationships between objects, e.g

      1) Person has many Roles
      2) Add Roles to Person
      3) Add Siblings to Persons etc etc
      4) Full DataModelSelection example, with addition and removal

      These are very basic i know. I looked through the documentation again and the examples, there is no concrete example that is easy to follow for the scenario i described above. At the very least I tried to modify the messages example to add messages and that failed.

      Most errors seem to be:
      1) Issues with the view state
      2) Detached entity issues (yes i know that is hibernate related and should be posted there)

      Rules in general like:
      - nullifying view object that are part of a selected element of DataModel ?
      - when adding child objects, do you need to do something like

       entityManager.persist(car)
       parent.setCar(car)
       entityManager.persist(child);
       parent.add(child)
       parent = entityManager.merge(parent)
      


      Ok i know the above is hibernate related, and i will look on the hibernate forums for it, or rather the ejb3 forums.

      Anyway, sorry for the rant :-| I'm jsut stuck and trying all sorts of things to get the functionality working properly



        • 1. Re: More seam examples
          Pete Muir Master

           

          Parent parent = new Parent();
          Child child = new Child();
          Car car = new Car();
          parent.setCar(car);
          parent.add(child);
          parent.persist(parent);
          


          Assuming car and child are entities with no references to parent and Parent is:

          @Entity
          public class Parent {
          
          @ManyToOne(cascade=PERSIST)
          private Car car;
          @OneToMany(cascade=PERSIST)
          private List<Child> children;
          
          ...
           // Getters and setters
          }
          


          If you had bi-directional relationships you might want

          entityManager.flush();
          entityManager.refresh(parent);
          


          as well.

          Nullifying view objects should work fine (empty fields) (but you need to make sure the new version is outjected which requires a reasonable understanding of the difference between variables in the component and context variables).

          Regarding relationships - this is really a Hibernate/EJB3 JPA issue. The hibernate unit tests are good for understanding the sematics involved.