I have the following Hibernate code:
List<Book> result;
result = hibernateTemplate.execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery("SELECT DISTINCT b FROM Book as b LEFT JOIN FETCH b.authors");
List list = query.list();
return list;
}
});
I am getting the following warnings starting at hibernateTemplate.execute(...
:
Multiple markers at this line
- HibernateCallback is a raw type. References to generic type HibernateCallback<T> should be parameterized
- Type safety: The expression of type new HibernateCallback(){} needs unchecked conversion to conform to HibernateCallback<Object>
- Type safety: Unchecked invocation execute(new HibernateCallback(){}) of the generic method execute(HibernateCallback<T>) of type
HibernateTemplate
- Type safety: The expression of type new HibernateCallback(){} needs unchecked conversion to conform to HibernateCallback<List<Book>>
- Type safety: The expression of type List needs unchecked conversion to conform to List<Book>
So this is really tough.
Could you please explain
What does the compiler see versus what it expects, and why?
What is the safest way to fix these warnings... i.e. not by
@SuppressWarnings("unchecked")
?
I have tried the proposal appearing in the following link: https://forums.oracle.com/forums/thread.jspa?threadID=1182661 (the second suggestion out of the three appearing at the bottom of the page).... however it did not work.
Thanks!
P.S. I do know how to solve the other warning I am supposed to get due to the List list = query.list();
, this is why I am not mentioning it in my question.
P.S-2 According to Eclipse, the signature of the method is <Object> Object org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateCallback<Object> action) throws DataAccessException