在我的 Spring-Hibernate 应用程序中,我有 4 个 bean 类,如 UserVO、BookVO、AttandanceVO 和 Timetable。
和我的 AttendanceVO 豆类:
@ManyToOne
@JoinColumn(name="BOOK_ID")
private BookVO book;
//Setters and getters.
和我的 BookVO 豆类:
@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 是时间表 ID,为什么 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
}