How do I use a custom select statement in Hibernate using the HibernateDaoSupport class
- by Bill Leeper
I am trying to write a custom select statement in Hibernate using the getHibernateTemplate() method. I am having problems with the resulting mapping.
Example Code:
List<User> users = getHibernateTemplate().find("Select user, sysdate as latestPost from User as user");
for (User user : users) {
assertNotNull(users.name);
}
The goal of the above line is to eventually have a join where I get the max(date) of posts made by the user. The problem I am having is that the resulting users list is not a list of User objects and I get a class cast exception.
Hopefully that is enough code. It is a greatly simplified version of my problem and a combination of snippets from various parts of my application.