I enter all object values in JSP page and when I press submit
button:
<h:panelGrid columns="4">
<h:outputText value="Employee name:"/>
<h:inputText id="eName"
value="#{employeeBean.employee.name}" required="true"
requiredMessage="#{msgs.nameRequired}">
</h:inputText>
<h:message for="eName" style="color:red"/>
<h:outputText value=" "/>
<h:outputText value="Employee role:"/>
<h:selectOneMenu value="#{employeeBean.role}">
<f:selectItems value="#{employeeBean.idNameRoleMap}"/>
</h:selectOneMenu>
</h:panelGrid>
<h:form><h:commandButton value="Submit" action="#{employeeBean.saveEmployee}"/></h:form>
</ui:define>
I get an exception:
javax.servlet.ServletException: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: Column 'NAME' cannot accept a NULL value.
Error Code: 20000
Call: INSERT INTO EMPLOYEE (BIRTHDATE, EMAIL, HIREDATE, NAME, PASSWORD, READY, role_id) VALUES (?, ?, ?, ?, ?, ?, ?)
bind => [7 parameters bound]
Query: InsertObjectQuery(Employee{id=0, name='null', email='null', password='null', birthDate=null, hireDate=null, ready=false, role=null})
All the fields passed as nulls as query shows. Bean method is:
public String saveEmployee() {
if (employee == null) {
employee = new Employee();
}
employee.setRole(idRoleMap.get(role));
employeeService.save(employee);
return "employeeList";
}
what's wrong with it?