2013-06-18 54 views
0

在我的Spring-Hibernate應用程序中,我有4個bean類,如UserVO,BookVO,AttandanceVO和Timetable。Hibernate異常:java.sql.SQLException:無效的值getInt() - 'T2'

和我AttendanceVO bean類:

@ManyToOne 
@JoinColumn(name="BOOK_ID") 
private BookVO book; 
//Setters and getters. 

和我BookVO bean類:

@ManyToOne 
@JoinColumn(name = "USER_ID") 
private UserVO user; 
@ManyToOne 
@JoinColumn(name = "Time_ID") 
private TimeTable timetable; 

//Setters and getters 

在我的Hibernate類我正在寫查詢..

@Transactional 
public List<AttendanceVO> findAttendanceList(UserVO user){ 
    TypedQuery<AttendanceVO> query = entityManager.createQuery("select av from AttendanceVO av inner join av.book bb where bb.user=:user", 
      AttendanceVO.class); 
    query.setParameter("user", user); 
    return query.getResultList(); 
} 

但我我得到異常像..

SEVERE: Servlet.service() for servlet [spring] in context with path [/EClass] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not load an entity: [com.sits.ec.valueObjects.BookVO#A2]] with root cause 
java.sql.SQLException: Invalid value for getInt() - 'T2' 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) 
.............. 

實際上是時間表身份證,爲什麼T2來聽說我要辦不包括在我的查詢時間表..

是他們的任何映射需要T2?

Edit 1: 


@Entity 
@Table(name = "BOOK") 
public class BookVO{ 

    @ManyToOne 
    @JoinColumn(name = "USER_ID") 
    private UserVO user; 

    @ManyToOne 
    @JoinColumn(name = "TIMETABLE_ID") 
    private TimetableVO timetable; 
//Setters and getters 
} 
+0

是的共享BookVO –

+0

共享其他域類和基本表結構... – Thihara

+0

與問題無關,但是,當您更改數據時,只應使用'@Transactional',不需要註釋時你只能選擇 –

回答

0

我的猜測是DB中有一些空值。當hibernate試圖映射類整數字段時,它拋出這個異常。這是發生在我身上的事情。下面我用在選擇caluse處理空值明確

ISNULL("column having null value", 0) 
+0

否.. DB對於特定用戶有1個值。 – SWEE

0

我不認爲你可以映射UserVO到DB基本類型,你應該檢查USER_ID列的數據類型,並映射該類型到你的代碼。 嘗試將映射類型從休眠狀態精確到你的數據庫。

相關問題