Когда я пытаюсь обновить объект User в моем тесте, я получаю следующий вывод:
2018-paź-26 22:18:24 PM [main] DEBUG org.hibernate.SQL - update "user" set "date_of_birth"=?, "email"=?, "login"=?, "password"=?, "user_rating"=? where "user_id"=?
2018-paź-26 22:18:24 PM [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [DATE] - [2018-10-26]
2018-paź-26 22:18:24 PM [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [VARCHAR] - [someEmail]
2018-paź-26 22:18:24 PM [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as[VARCHAR] - [updatedLogin]
2018-paź-26 22:18:24 PM [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [VARCHAR] - [somePassword]
2018-paź-26 22:18:24 PM [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [FLOAT] - [0.0]
2018-paź-26 22:18:24 PM [main] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [6] as [BIGINT] - [5]
2018-paź-26 22:18:24 PM [main] DEBUG org.hibernate.SQL - update "user" set date_of_birth=?, "email"=?, "login"=?, "password"=?, user_rating=? where "user_id"=?
2018-paź-26 22:18:24 PM [main] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 42122, SQLState: 42S22
2018-paź-26 22:18:24 PM [main] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Kolumna "DATE_OF_BIRTH" nie istnieje
Column "DATE_OF_BIRTH" not found; SQL statement:
update "user" set date_of_birth=?, "email"=?, "login"=?, "password"=?, user_rating=? where "user_id"=? [42122-197]
User.class
@Entity
@Table(name = "user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id")
private long id;
@Column(name = "email")
private String email;
@Column(name = "login")
private String login;
@Column(name = "password")
private String password;
@Column(name = "date_of_birth")
private LocalDate dateOfBirth;
@Column(name = "user_rating")
private float userRating;
//Getters and setters ommited for clarity
И метод обновления в реализации dao:
@Override
public void update(User user) {
log.info("Update user with id= " + user.getId() + ", set email= " + user.getEmail()
+ ", login = " + user.getLogin() + ", dateOfBirth= " + user.getDateOfBirth());
Query query = getSession().createQuery("update User"
+ " set date_of_birth = :dateOfBirth,"
+ " email = :email,"
+ " login = :login,"
+ " password = :password,"
+ " user_rating = :userRating where id = :id");
query.setParameter("email", user.getEmail());
query.setParameter("login", user.getLogin());
query.setParameter("dateOfBirth", user.getDateOfBirth());
query.setParameter("password", user.getPassword());
query.setParameter("userRating", user.getUserRating());
query.setParameter("id", user.getId());
int result = query.executeUpdate();
log.info("Update result: " + result);
}
Для другого теста, где я получаю пользователя из базы данных или сохраняю, нет проблем со столбцом "date_of_birth".
PS В треке стека я обнаружил, что столбец sql date_of_birthне в кавычках, когда в других тестах всегда появляются кавычки, возможно, проблема здесь?
org.hibernate.SQL - update "user" set date_of_birth=?, "email"=?, "login"=?, "password"=?, user_rating=? where "user_id"=?