2012-02-02 514 views
4

我在休眠以下實體:SQLStateConverter.handledNonSpecificException冬眠

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

當我打電話休眠的這個方法:

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

EDITED

我調試它更多,看到的例外是:

Bad format for DATE '517' in column 2. 

有日期:1985年5月17日

+0

是什麼日子列的數據庫中的數據類型和RDBMS是什麼呢? – centic 2012-02-04 20:47:56

+0

@centic類型是Date和數據。 RDMBS是什麼意思?我的MySQL – Dejell 2012-02-04 21:16:56

回答

4

非常非常愚蠢的問題。

在Hibernate中字段的名稱是birthday而在DB我是registration_date

birthday在DB是一個int場..

1

您可以使用符號沿Hibernate實現JPA

@Column(name="registration_date") 
private Date birthday; 

的未來因此,你不必改變數據庫列的名稱。

乾杯