-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Combining Projections and Query by Example question
PostPosted: Mon Mar 20, 2006 1:29 pm 
Newbie

Joined: Mon Mar 20, 2006 1:16 pm
Posts: 5
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.