-->
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: Projects/Subqueries w/composite keys
PostPosted: Mon Nov 22, 2010 3:55 pm 
Beginner
Beginner

Joined: Fri Nov 13, 2009 4:05 pm
Posts: 30
I have an entity whose id is a composite of several fields. I am trying to do a detached criteria query against several child records but have the result returned as the parent object. I read that the way to do this was to do a projection on the id, then use this id in a second query to get the distinct list of records. Normally one wouldn't have to do this but since we're wanting to restrict the records returned by paging to avoid unnecessary memory consumption, we do.

Code:
  DetachedCriteria dc = DetachedCriteria.forClass(RequestForQuotation.class);
  /* set the criteria restrictions here */
  dc.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
  dc.setProjection(Projections.id());

  Criteria criteria = session.createCriteria(RequestForQuotation.class);
  criteria.add(Subqueries.propertyIn("id", dc));
  criteria.setFirstRow((pageNumber-1)*pageSize).setMaxResults(pageSize);
  return(criteria.list());


By using the above code I get the following error:
property does not map to a single column: id

Ironically if I move from detached criteria to regular criteria, this works, but the goal was not to perform two list() calls to obtain the data which should be available via the Subqueries class.

Code:
  Criteria dc = session.createCriteria(RequestForQuotation.class);
  /* set the criteria restrictions here */
  dc.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
  dc.setProjection(Projections.id());

  List<RequestForQuotationId> ids = dc.list();

  Criteria criteria = session.createCriteria(RequestForQuotation.class);
  criteria.add(Restrictions.in("id", ids));
  criteria.setFirstRow((pageNumber-1)*pageSize).setMaxResults(pageSize);
  return(criteria.list());


Can anyone share how I could fix this?


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.