-->
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.  [ 2 posts ] 
Author Message
 Post subject: criteria's strange behavior
PostPosted: Thu Aug 27, 2009 3:41 pm 
Newbie

Joined: Thu Aug 27, 2009 3:15 pm
Posts: 2
Hi folks,

I am trying to use criteria API to achieve following query
Code:
SELECT P.* FROM PRODUCT P, ORDERS O WHERE P.PID=O.PID AND O.STATUS=1


I have two tables product and orders, and i want to see all products against each order status, also order detail for each product, for same in my product.hbm.xml i have a set property for orders named OrderDetails

I am using criteria in following way
Code:
criteria = oSession.createCriteria(Product.class);
criteria.createCriteria("OrderDetails","ord",CriteriaSpecification.INNER_JOIN);
criteria.add(Restrictions.in("ord.statusID.id", Ids));
criteria.setMaxResults(50);


1st problem
when i look at the generated query it gives me query like this
Code:
SELECT P.*, O.* FROM PRODUCT P, ORDERS O WHERE P.PID=O.PID AND O.STATUS=1


2nd problem
This is returning me duplicate records as well, so to overcome this i had put
Code:
criteria.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY );

however even after setting pagesize as 50, this returns me less then 50 rows even though there are 100+ rows available with this criteria in database.

Basically criteria is not fetching the next page rows if resultset is shorter then defined page size.

Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject: Re: criteria's strange behavior
PostPosted: Thu Aug 27, 2009 6:14 pm 
Newbie

Joined: Thu Aug 27, 2009 3:15 pm
Posts: 2
Let me make it simple
I wan to produce following query using criteria API

Code:
SELECT P.* FROM PRODUCT P, ORDERS O WHERE P.PID=O.PID AND O.STATUS=1


What criteria i should write??


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.