2 Replies Latest reply on Jun 24, 2009 2:33 PM by Goh Benjamin

    Seam-gen and

    Goh Benjamin Newbie

      Hi,


      I'm currently using Seam 2.1.2.GA on JBoss 5.1.0.GA.  I am new to Seam, and am trying out a simple example via the use of seam-gen.  My seam setup is configured to deploy to a WAR, using MySQL as a database, with RichFaces components for JSF.


      I have 2 entity beans I coded by hand, which form a simple master-detail relationship:


      @Entity
      @Name("fruitFamily")
      public class FruitFamily {
      
        @Id @GeneratedValue
        private Long id;
        
        @Version
        private Long version;
        
        @NotNull
        private String name;
        
        @OneToMany(mappedBy="fruitFamily")
        private Set<Fruit> fruits;
      
        // getters and setters as generated by Eclipse
          
      }
      



      @Entity
      @Name("fruit")
      public class Fruit {
        
        @Id @GeneratedValue
        private Long id;
        
        @Version
        private Long version;
        
        @NotNull @Length(max=100)
        private String name;
        
        @NotNull
        private Boolean poisonous;
        
        @ManyToOne
        private FruitFamily fruitFamily;  
      
        // getters and setters generated by Eclipse
      
      }



      After writing these classes, I ran seam generate-ui and decided to give the generated CRUDs a spin.  However, when I try to create a FruitFamily I get an exception in the xhtml page:


      javax.el.ELException: /FruitFamilyEdit.xhtml @79,68 rendered="#{empty fruitFamilyHome.fruits}": Error reading 'fruits' on type FruitFamilyHome_$$_javassist_seam_4



      My understanding is that adding the mappedBy clause to the @OneToMany annotation causes seam-gen to create jsf codes to display the list of child objects associated with the parent object.  If I remove the clause, I do not get this exception.


      I am not sure how to proceed at this point.  Am I making a mistake in how I code my Entity classes?  Is there a better approach to how I'm doing things?


      Thanks in advance.

        • 1. Re: Seam-gen and
          Goh Benjamin Newbie

          Gah... sorry about the title.  I meant to name it something like Difficulties with Seam-gen and master-detail relationships.

          • 2. Re: Seam-gen and
            Goh Benjamin Newbie

            Nevermind.  I believe I have figured it out.  I tried doing it in reverse, using generate-model to generate the Entity beans, and I discovered that the line


            @OneToMany(mappedBy="fruitFamily")
              private Set<Fruit> fruits;



            was slightly different from the one generated by seam-gen.  In particular, the set had a default initialized value rather than being null.


            private Set<Fruit> fruits = new HashSet<Fruit>();



            This seemed to solve the problem.