How do I use a custom select statement in Hibernate using the HibernateDaoSupport class

Posted by Bill Leeper on Stack Overflow See other posts from Stack Overflow or by Bill Leeper
Published on 2010-04-19T18:45:58Z Indexed on 2010/04/19 18:53 UTC
Read the original article Hit count: 185

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate