作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 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/
我在 Hibernate 中有以下实体: @Entity public class Contact implements Serializable { private static final
我是一名优秀的程序员,十分优秀!