7 Replies Latest reply on Jun 5, 2007 1:59 PM by trickyvail

    EntityHome validation error (Chapter 14 example)

      I am just getting started with SEAM. I tried the first few examples, and got them working, so in my exuberence I decided to try out the EntityHome example in chapert 14 of the onling doc. Whenever I try to persist the Person, it fails with validation errors. What is interesting is that the validation errors cause the page to fail instead of displaying the errors in the browser like the previous examples do. The root of the problem is:

      Caused by: org.hibernate.validator.InvalidStateException: validation failed for: org.jboss.seam.example.registration.Person

      I cannot for the life of me figure out why validation is failing. My entity bean, entityhome, and jspx page is displayed below. Any hints on what the problem is would be appreciated. I have not idea how to troubleshoot this problem, so any help at all would be appreciated.

      Entity Bean :

      @Entity
      @Table(name="persontable")
      public class Person {
       private Long id;
       private String firstName;
       private String lastName;
       //private Country nationality;
       @Id @NotNull @GeneratedValue
       public Long getId() {
       return id;
       }
       @Column(name="firstname",length = 45)
       @Length(max = 45)
       public String getFirstName() {
       return firstName;
       }
      
       @Column(name="lastname", length = 45)
       @Length(max = 45)
       public String getLastName() {
       return lastName;
       }
      
       public void setFirstName(String firstName) {
       this.firstName = firstName;
       }
      
       public void setId(Long id) {
       this.id = id;
       }
      
       public void setLastName(String lastName) {
       this.lastName = lastName;
       }
      
      }
      


      EntityHome:
      @Name("personHome")
      public class PersonHome extends EntityHome<Person> {
       /**
       *
       */
       private static final long serialVersionUID = 219059304048820709L;
       @RequestParameter Long personId;
       @In EntityManager entityManager;
      
       public Object getId() { return personId; }
       public EntityManager getEntityManager() { return entityManager; }
      
      }
      


      Page:
      <?xml version="1.0"?>
      <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns="http://www.w3.org/1999/xhtml"
       version="2.0">
       <jsp:output doctype-root-element="html"
       doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
       doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
       <jsp:directive.page contentType="text/html"/>
       <html>
       <head>
       <title>Register New User</title>
       </head>
       <body>
       <f:view>
      <h1>Create Person</h1>
      <h:form>
      <s:validateAll>
      
       <div>First name: <h:inputText value="#{personHome.instance.firstName}"/></div>
       <div>Last name: <h:inputText value="#{personHome.instance.lastName}"/></div>
      </s:validateAll>
       <div>
       <h:messages/>
       <h:commandButton value="Create Person" action="#{personHome.persist}"/>
       </div>
      
      </h:form>
       </f:view>
       </body>
       </html>
      </jsp:root>
      
      


        • 1. EntityHome validation error (Chapter 14 example)
          trickyvail

          I think you mave have failed to instantiate an instance of Person inside EntityHome.

          @Name("personHome")
          public class PersonHome extends EntityHome<Person> {
          
           private static final long serialVersionUID = 219059304048820709L;
          
           public void setPersonId(Long id)
           {
           setId(id);
           }
          
           public Long getPersonId()
           {
           return (Long) getId();
           }
          
           @Override
           protected Person createInstance()
           {
           Person person = new Person();
           return person;
           }
          }
          



          • 2. Re: EntityHome validation error (Chapter 14 example)
            pmuir

            No, that createInstance method does nothing. Honestly, I'm not sure the code snippets in the Framework chapter fit together to make a complete app (they should do probably). Best off generating a an app using seam-gen, this uses the Framework - you can refer back to the Framework chapter to find out how it ties together.

            http://jira.jboss.com/jira/browse/JBSEAM-1258

            • 3. Re: EntityHome validation error (Chapter 14 example)

              I did try to reference the seam-gen application, but it was a bit overwhelming. There was so many files generated, I had a hard time "seeing the forest from the trees". My hope was the EntityHome could save me alot of work for simple CRUD applications, but would I be better off using Session beans and the like instead of figuring out the EntityHome configuration? Anyone use the EntityHome in a produciton environement? Anyone know what the pros and cons are?

              • 4. Re: EntityHome validation error (Chapter 14 example)
                pmuir

                EntityHome will save you days if not weeks and they also provide a great base for building an application that uses pages.xml for the wiring (which IMO is the best pattern for building a Seam app). I use them for a (small) production app - working well. A basic seam-gen app, with no reverse engineering shouldn't have too many files that are related to the actual app (ignore everything except classes, components.xml, pages.xml, .page.xml and .xhtml files).

                • 5. Re: EntityHome validation error (Chapter 14 example)

                  Seam's power is such that you're able to directly expose EntityHome objects in the view and use pages.xml to wire it all together, and even provide security. However, if you prefer to do things in code, just think of EntityHome as an implementation of the "Generic DAO" pattern that plays nice with SMPC's -- because that's all it really is.

                  I find it's impossible to have even reasonably complex views without a backing session bean anyway, so I much prefer to have all CRUD actions go through the session bean that simply injects the EntityHome itself. TMTOWTDI.

                  • 6. Re: EntityHome validation error (Chapter 14 example)
                    saeediqbal1

                     

                    "cja987" wrote:
                    ... prefer to have all CRUD actions go through the session bean that simply injects the EntityHome itself. TMTOWTDI.


                    what are you saying?

                    • 7. Re: EntityHome validation error (Chapter 14 example)
                      trickyvail

                      TMTOWTDI = there's more than one way to do it (it's an acronym popularized by PERL).