In my Spring-Hibernate Application, i have 4 bean classes like UserVO,BookVO,AttandanceVO and Timetable.
and my AttendanceVO bean class:
@ManyToOne
@JoinColumn(name="BOOK_ID")
private BookVO book;
//Setters and getters.
and my BookVO bean class:
@ManyToOne
@JoinColumn(name = "USER_ID")
private UserVO user;
@ManyToOne
@JoinColumn(name = "Time_ID")
private TimeTable timetable;
//Setters and getters
In my Hibernate class i'm writing query ..
@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();
}
But i'm get Exception like..
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)
..............
Actually T2 is Timetable Id, why T2 coming hear i'm not include timetable in my query ..
Is their any mapping needed?
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
}
My guess is there is some null value in DB. when hibernate tried to map with class integer field, it throwing this exception. This is what happened to me. I used below in select caluse to handle null value explicitly
ISNULL("column having null value", 0)
i dont think you can map UserVO to DB primitive types , you should check the datatype of USER_ID column , and map that type to your code. try to exact map types from hibernate to your db.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.