gpt4 book ai didi

java - SQLStateConverter.handledNonSpecificException hibernate

转载 作者:可可西里 更新时间:2023-11-01 07:31:20 24 4
gpt4 key购买 nike

我在 Hibernate 中有以下实体:

@Entity
public class Contact implements Serializable {
private static final long serialVersionUID = 1L;
@Temporal(TemporalType.DATE)
private Date birthday;
}

当我调用hibernate的这个方法时:

public Object get(Class entityClass, Serializable id) throws HibernateException {
return get( entityClass.getName(), id );
}

我得到以下异常:

org.hibernate.exception.GenericJDBCException: could not load an entity: [com.mycompany.model.Contact#3]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
}

我试过这个简单的代码:

Statement st = conn.createStatement();
ResultSet res = st.executeQuery("select registration_date from contact where contact_id=3");
Date i = res.getDate(1);

这很好用。

问题是什么?

在这两种情况下,Date 的类型都是 java.util.Date

已编辑

调试多了,看到异常是:

Bad format for DATE '517' in column 2.

那里的日期是:1985-05-17

最佳答案

非常非常愚蠢的问题。

Hibernate 中的字段名称是 birthday 而在数据库中我是 registration_date

数据库中的

birthday 是一个 int 字段..

关于java - SQLStateConverter.handledNonSpecificException hibernate ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9115625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com