Hibernate version:3.1
I am having a problem trying to do a Criteria query by example as follows...
Code:
public List findByExample2(SfaAccountsSearchV instance) {
return getCurrentSession().createCriteria( SfaAccountsSearchV.class)
.setProjection( Projections.distinct( Projections.projectionList()
.add( Projections.property("city"), "city")
.add( Projections.property("state"), "state")))
.add( Example.create( instance))
.setResultTransformer( new AliasToBeanResultTransformer(SfaAccountsSearchV.class))
.list();
}
I pass in an entity and return a collection of partially populated entities that match it.
This works fine for inputs that search on say, zip code. I get this query...
Hibernate: select distinct this_.CITY as y0_, this_.STATE as y1_ from SFA.SFA_ACCOUNTS_SEARCH_V this_ where (this_.ZIP=?)
However, when I set city or state in the input I get a query with a broken where clause like this...
Hibernate: select distinct this_.CITY as y0_, this_.STATE as y1_ from SFA.SFA_ACCOUNTS_SEARCH_V this_ where (y1_=?)
I tried changing it to
.add( Projections.property("state"))))
and the query is correct but the state field is not populated in the returned collection.
Am I doing something wrong or should this work?