-->
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.  [ 4 posts ] 
Author Message
 Post subject: Criteria mixing projection and entity
PostPosted: Thu Oct 27, 2005 4:30 am 
Newbie

Joined: Thu Aug 04, 2005 12:45 pm
Posts: 4
Is there any way I can create a Criteria query that return an Entity and a projection at the same time?

I want to retrieve an Entity list, and also include a specially calculated field for each one. The special field uses a custom function, which takes a parameter. Adding projections seems to force it into projection mode, and i can't get the primary entity.

Alternatively, I've tried to use Query, but it won't take a custom function, or tries to parse an ARRAY construct I pass in.

I would just use a native Sql Query, but I don't want to map each field in every case.

Please help! thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 8:57 pm 
Newbie

Joined: Thu May 26, 2005 6:31 pm
Posts: 19
Anyone has an answer of this? It may also answer my pagination question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 6:11 am 
Newbie

Joined: Mon Oct 24, 2005 2:51 pm
Posts: 7
No that is not posible.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 6:38 am 
Newbie

Joined: Fri Nov 04, 2005 4:47 am
Posts: 14
I don't understand your first question fully, but if your pagination problem is the same as mine, you need to get the count of the full result, and then just retrieve the selected page. I found the answer to this problem searching this forum:

First, to count:

Code:
criteria.setProjection(Projections.rowCount());
Integer count = (Integer) criteria.uniqueResult();


Then, just afterwards to get the criteria back into "normal" mode:

Code:
criteria.setProjection(null);
criteria.setResultTransformer(Criteria.ROOT_ENTITY);


I was using a ScrollingResult to get the count, and on MySQL this was taking close to a second. With a projection query it's taking 50ms.


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

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.