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?


      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() {}
       public long getId() {
       return id;
       public void setId(long id) {
       this.id = id;

      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;
       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 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 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 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 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 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"/>

      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:

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

          • 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?


            • 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.


              I appreciate it.


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

                sorry, that was supposed to be a new topic.