找不到“ DATE_OF_BIRTH”列; SQL语句:

时间:2018-10-26 21:05:08

标签: sql spring hibernate hql

当我尝试在测试中更新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”列没有问题。

P.S。在堆栈跟踪中,我发现sql date_of_birth列不在引号中,而在其他测试中,引号始终出现,问题可能出在这里吗?

org.hibernate.SQL - update "user" set date_of_birth=?, "email"=?, "login"=?, "password"=?, user_rating=? where "user_id"=?

0 个答案:

没有答案