4 Replies Latest reply on Mar 27, 2006 3:38 PM by John

    Joined subclass - insert failing

    John Newbie

      I've got a base class, Person, and a joined subclass, Recruiter.
      My facelet has input fields that are mapped to the Recruiter subclass.
      When I call the create method on the stateful session bean, I get a JDBC error. Why is it complaining about the hireDate field? It's in my form.
      Here are some code snippets. Anyone see the problem?

      Thanks,
      John

      @Entity
      @Inheritance(strategy=InheritanceType.JOINED)
      @Name("person")
      @Scope(EVENT)
      @Table(name="person")
      public class Person implements Serializable {
       private long id;
       private String firstname;
       private String middlename;
       private String lastname;
       private String address;
       private String socialSecurityNum;
       private String emailWork;
       private String emailPersonal;
       private String phoneWork;
       private String phoneWorkExtension;
       private String phoneHome;
       private String phoneCell;
       private String jobTitle;
      
       public Person() {}
      
       @Id(generate=GeneratorType.AUTO)
       public long getId() {
       return id;
       }
      
       public void setId(long id) {
       this.id = id;
       }
      

      @Entity
      @Name("recruiter")
      @Scope(EVENT)
      @Table(name="recruiter")
      public class Recruiter extends Person implements Serializable {
       private java.util.Date hireDate;
       private int recruiterType;
       private int terminatedFlag;
       private java.util.Date terminatedDate;
       private int commissionType;
       private double amount;
       private boolean amountDueFromCommissions;
      
       @NotNull
       public java.util.Date getHireDate() {
       return hireDate;
       }
      
       public void setHireDate(java.util.Date hireDate) {
       this.hireDate = hireDate;
       }
      

      <div class="label"><h:outputLabel for="firstname">First name:</h:outputLabel></div>
      <div class="input"><h:inputText id="firstname" value="#{recruiter.firstname}"/><br/><span class="errors"><h:message for="firstname" /></span></div>
      </div>
      <div class="label"><h:outputLabel for="lastname">Last Name:</h:outputLabel></div>
      <div class="input"><h:inputText id="lastname" value="#{recruiter.lastname}" /><br/><span class="errors"><h:message for="lastname" /></span></div>
      </div>
      <div class="label"><h:outputLabel for="socialSecurityNum">SSN:</h:outputLabel></div>
      <div class="input"><h:inputText id="socialSecurityNum" value="#{recruiter.socialSecurityNum}" /><br/><span class="errors"><h:message for="socialSecurityNum" /></span></div>
      </div>
      <div class="label"><h:outputLabel for="address">Address:</h:outputLabel></div>
      <div class="input"><h:inputText id="address" value="#{recruiter.address}" /><br/><span class="errors"><h:message for="address" /></span></div>
      </div>
      <div class="label"><h:outputLabel for="hireDate">Hire date:</h:outputLabel></div>
      <div class="input"><h:inputText id="hireDate" value="#{recruiter.hireDate}"><f:convertDateTime type="date"/></h:inputText><br/><span class="errors"><h:message for="hireDate" /></span></div>
      </div>
      <div class="entry errors"><h:messages globalOnly="true" /></div>
      <div class="label"> </div>
      <div class="input"><h:commandButton value="Create" action="#{createRecruiter.createRecruiter}" class="button"/> 
      <h:commandButton value="Cancel" action="login" class="button"/>
      </div>
      


      12:16:29,112 INFO [STDOUT] Hibernate: insert into person (address, lastname, socialSecurityNum, firstname, middlename, emailPersonal, emailWork, jobTitle, phoneCell, phoneHome, phoneWork, phoneWorkExtension) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
      12:16:29,132 WARN [JDBCExceptionReporter] SQL Error: 1364, SQLState: HY000
      12:16:29,132 ERROR [JDBCExceptionReporter] Field 'hireDate' doesn't have a default value
      12:16:29,142 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception


        • 1. Re: Joined subclass - insert failing
          John Newbie

          Here is the stateful session bean:

          @Stateful
          @Scope(EVENT)
          @Name("createRecruiter")
          @Interceptor(SeamInterceptor.class)
          public class CreateRecruiterAction implements CreateRecruiter {
          
           private static final Logger log = Logger.getLogger(CreateRecruiter.class);
          
           @In @Valid
           private Recruiter recruiter;
          
           @PersistenceContext
           private EntityManager em;
          
           @In
           private FacesContext facesContext;
          
           @IfInvalid(outcome=REDISPLAY)
           public String createRecruiter() {
           log.info("creating recruiter");
           List existing = em.createQuery("select socialSecurityNum from Person where socialSecurityNum=:socialSecurityNum")
           .setParameter("socialSecurityNum", recruiter.getSocialSecurityNum())
           .getResultList();
           if (existing.size()==0) {
           em.persist(recruiter);
           em.flush();
           return "login";
           } else {
           //String ssno = existing.get(0);
           facesContext.addMessage(null, new FacesMessage("recruiter already exists"));
           return null;
           }
           }
          
           @Destroy @Remove
           public void destroy() {
           log.info("destroyed");
           }
          }
          


          • 2. Re: Joined subclass - insert failing
            John Newbie

            Another update. I logged the value of hireDate before the insert and it does have the correct input value. Is there something wrong with how I called the persist method? Anyone done this before?

            Thanks,
            John

            • 3. Re: Joined subclass - insert failing
              John Newbie

              Anyone able to provide some input? I'm a newbie and I'm trying to get started. Please let me know if I can explain anything further.

              http://www.jboss.com/index.html?module=bb&op=viewtopic&t=79644

              I appreciate it.

              Thanks,
              John

              • 4. Re: Joined subclass - insert failing
                John Newbie

                sorry, that was supposed to be a new topic.