У меня проблема с созданием записей о сотрудниках в моем веб-приложении (с использованием spring, hibernate, thymeleaf и mySQL db).Вставка Hibernate возвращает нулевые параметры привязки и завершается неудачей с помощью следующего действияНе могли бы вы взглянуть на это?Может кто знает, что тут может быть не так.
[nio-8090-exec-6] org.hibernate.SQL :
insert
into
temployee
(account_status, account_type, birth_day, branch, city, department,
email_address, first_name, full_name, home_nbr, is_manager, last_name,
phone_number, position, position_desc, post_code, state, street, valid_from,
valid_until)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2018-10-24 14:56:22.064 TRACE 14272 --- [nio-8090-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [null]
Для всех атрибутов из db insert?
Мой Сотрудник Класс сущности:
package com.project.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan(basePackages= {"com.project.*"})
@Entity
@Table(name="TEMPLOYEE", schema= "mydb")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="EMPLOYEE_ID")
public int employee_id;
@Column(name="FIRST_NAME")
public String first_name;
@Column(name="LAST_NAME")
public String last_name;
@Column(name="FULL_NAME")
public String full_name;
@Column(name="EMAIL_ADDRESS")
public String email_address;
@Column(name="PHONE_NUMBER")
public String phone_number;
@Column(name="ACCOUNT_TYPE")
public String account_type;
@Column(name="ACCOUNT_STATUS")
public String account_status;
@Column(name="VALID_FROM")
public String valid_from;
@Column(name="VALID_UNTIL")
public String valid_until;
@Column(name="IS_MANAGER")
public String is_manager;
@Column(name="STREET")
public String street;
@Column(name="HOME_NBR")
public String home_nbr;
@Column(name="CITY")
public String city;
@Column(name="STATE")
public String state;
@Column(name="POST_CODE")
public String post_code;
@Column(name="BIRTH_DAY")
public String birth_day;
@Column(name="BRANCH")
public String branch;
@Column(name="DEPARTMENT")
public String department;
@Column(name="POSITION")
public String position;
@Column(name="POSITION_DESC")
public String position_desc;
public int getEmployeeID() {
return employee_id;
}
public void SetEmployeeID(int employee_id) {
this.employee_id = employee_id;
}
public String getFirstName() {
return first_name;
}
public void SetFirstName(String first_name) {
this.first_name = first_name;
}
public String getLastName() {
return last_name;
}
public void SetLastName(String last_name) {
this.last_name = last_name;
}
public String getFullName() {
return full_name;
}
public void SetFullName(String full_name) {
this.full_name = full_name;
}
public String getEmailAddress() {
return email_address;
}
public void SetEmailAddress(String email_address) {
this.email_address = email_address;
}
public String getPhoneNumber() {
return phone_number;
}
public void SetPhoneNumber(String phone_number) {
this.phone_number = phone_number;
}
public String getAccountType() {
return account_type;
}
public void SetAccountType(String account_type) {
this.account_type = account_type;
}
public String getAccountStatus() {
return account_status;
}
public void SetAccountStatus(String account_status) {
this.account_status = account_status;
}
public String getValidFrom() {
return valid_from;
}
public void SetValidFrom(String valid_from) {
this.valid_from = valid_from;
}
public String getValidUntil() {
return valid_until;
}
public void SetValidUntil(String valid_until) {
this.valid_until = valid_until;
}
public String getIsManager() {
return is_manager;
}
public void SetIsManager(String is_manager) {
this.is_manager = is_manager;
}
public String getStreet() {
return street;
}
public void SetStreet(String street) {
this.street = street;
}
public String getHomeNbr() {
return home_nbr;
}
public void SetHomeNbr(String home_nbr) {
this.home_nbr = home_nbr;
}
public String getCity() {
return city;
}
public void SetCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void SetState(String state) {
this.state = state;
}
public String getPostCode() {
return post_code;
}
public void SetPostCode(String post_code) {
this.post_code = post_code;
}
public String getBirthDay() {
return birth_day;
}
public void SetBirthDay(String birth_day) {
this.birth_day = birth_day;
}
public String getBranch() {
return branch;
}
public void SetBranch(String branch) {
this.branch = branch;
}
public String getDepartment() {
return department;
}
public void SetDepartment(String department) {
this.department = department;
}
public String getPosition() {
return position;
}
public void SetPosition(String position) {
this.position = position;
}
public String getPositionDesc() {
return position_desc;
}
public void SetPositionDesc(String position_desc) {
this.position_desc = position_desc;
}
}
И добавить методы сотрудника:
UserInfoConttroler класс:
//For add and update person both
@RequestMapping(value= "/employee/add", method = RequestMethod.POST)
public String addEmployee(@ModelAttribute("employee") Employee p){
if(p.getEmployeeID() == 0){
//new person, add it
this.employeeService.addEmployee(p);
}else{
//existing person, call update
this.employeeService.updateEmployee(p);
}
return "redirect:/employess";
}
EmployeeDAOImpl класс:
@Transactional
public Employee addEmployee(Employee employee) {
entityManager.persist(employee);
return employee;
}
@Transactional
public Employee updateEmployee(Employee employee) {
entityManager.merge(employee);
return employee;
}
И мое отображение формы сообщения в HTML (с использованием Thymeleaf):
<form method="post" name="addEmployee" id="addEmployee"
th:action="@{/employee/add}" role="form">
<form:hidden path="employee_id"/>
First Name:<br>
<input type="text" th:text="*{employee.first_name}" /><br>
Last Name:<br>
<input type="text" th:text="*{employee.last_name}" /><br>
Full Name:<br>
<input type="text" th:text="*{employee.full_name}" /><br>
Email:<br>
<input type="text" th:text="*{employee.email_address}" /><br>
Phone Number:<br>
<input type="text" th:text="*{employee.phone_number}" /><br>
Account Type:<br>
<input type="text" th:text="*{employee.account_type}" /><br>
Account Status:<br>
<input type="text" th:text="*{employee.account_status}" /><br>
Valid from:<br>
<input type="text" th:text="*{employee.valid_from}" /><br>
Valid until:<br>
<input type="text" th:text="*{employee.valid_until}" /><br>
IS Manager?:<br>
<input type="text" th:text="*{employee.is_manager}" /><br>
Street:<br>
<input type="text" th:text="*{employee.street}" /><br>
Home number:<br>
<input type="text" th:text="*{employee.home_nbr}" /><br>
City:<br>
<input type="text" th:text="*{employee.city}" /><br>
State:<br>
<input type="text" th:text="*{employee.state}" /><br>
Post code:<br>
<input type="text" th:text="*{employee.post_code}" /><br>
Birth Day:<br>
<input type="text" th:text="*{employee.birth_day}" /><br>
Branch:<br>
<input type="text" th:text="*{employee.branch}" /><br>
Deparnment:<br>
<input type="text" th:text="*{employee.department}" /><br>
Position:<br>
<input type="text" th:text="*{employee.position}" /><br>
Position Description:<br>
<input type="text" th:text="*{employee.position_desc}" /><br>
<input type="submit" value="Submit" /> <input type="reset"
value="Reset"/><br>
</form>
Добавление описания таблицы базы данных * Имя поля Тип NULL
EMPLOYEE_ID int (11) NO
FIRST_NAME varchar (20) NO
LAST_NAME varchar (20) NO
FULL_NAME varchar (45) ДА
EMAIL_ADDRESS varchar (60) ДА UNI
PHONE_NUMBER varchar (12) ДА
ACCOUNT_TYPE varchar (45) НЕТ
ACCOUNT_STATUS varchar (1) NO
VALID_FROM дата NO
VALID_UNTIL дата YES
IS_MANAGER varchar (1) NO
STREET varchar (100) NO
HOME_NBR varchar (45) YES
CITvarchar (100) NO
STATE varchar (100) NO
POST_CODE varchar (10) NO
BIRTH_DAY date NO
ФИЛИАЛ varchar (45) NO
DEPARTMENT varchar (45) NO
POSITION varchar (100) NO
POSITION_DESC varchar (255) ДА
Любая помощь будет оценена!Заранее спасибо!