Hi,
I'm trying to return a list of a bean that contains a subset of the original entity, but I'm doing this wrong somehow I guess.
Normal way to return a complete list (User is my entity).
Code:
public List<User> list() {
return (List<User>) session.createCriteria(User.class).list();
}
Now I instead wanted to return a list of AdminListUser instead, I thought I just could do this:
Code:
public List<AdminListUser> adminList() {
return (List<AdminListUser>) session.createCriteria(User.class).setResultTransformer(
Transformers.aliasToBean(AdminListUser.class)).list();
}
but then I get an exception.
Hibernate version:
3.2.5.ga
Full stack trace of any exception that occurs:
Caused by: org.hibernate.PropertyNotFoundException: Could not find setter for this on class nu.localhost.anopo.logic.beans.AdminListUser
at org.hibernate.property.ChainedPropertyAccessor.getSetter(ChainedPropertyAccessor.java:44)
at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:57)
at org.hibernate.loader.criteria.CriteriaLoader.getResultColumnOrRow(CriteriaLoader.java:115)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at nu.localhost.anopo.logic.dao.impl.UserDaoImpl.adminList(UserDaoImpl.java:68)
Name and version of the database you are using:
PostgreSQL 8.2.4
The generated SQL (show_sql=true):
Hibernate: select this_.user_id as user1_1_0_, this_.name as name1_0_, this_.password as password1_0_, this_.username as username1_0_, this_.enabled as enabled1_0_, this_.email as email1_0_, this_.expires as expires1_0_ from users this_