-->
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.  [ 3 posts ] 
Author Message
 Post subject: Question on creating criteria
PostPosted: Tue Aug 16, 2005 3:42 pm 
Newbie

Joined: Tue Jun 14, 2005 10:54 am
Posts: 4
Hi,
I am trying to create a sql expression that looks like

SELECT qualValue FROM QUALIFIER_VALUES WHERE type_id IN (SELECT qualTypeId FROM FUNCTION WHERE function_id='?')

Criteria criteriaValues = session.createCriteria(QualifierValues.class);
Criteria criteriaTypes = criteriaValues.createCriteria("qualifierTypes");
Criteria criteriaFunctions = criteriaTypes.
add(Expression.eq("id", new Integer(arg_functionId)));


As you would notice it would give me back types whose id i supply in. How would i include the type_id in the criteria query.


Top
 Profile  
 
 Post subject: Re: Question on creating criteria
PostPosted: Tue Aug 16, 2005 7:22 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
ve1224 wrote:
Hi,
I am trying to create a sql expression that looks like

SELECT qualValue FROM QUALIFIER_VALUES WHERE type_id IN (SELECT qualTypeId FROM FUNCTION WHERE function_id='?')

Criteria criteriaValues = session.createCriteria(QualifierValues.class);
Criteria criteriaTypes = criteriaValues.createCriteria("qualifierTypes");
Criteria criteriaFunctions = criteriaTypes.
add(Expression.eq("id", new Integer(arg_functionId)));


As you would notice it would give me back types whose id i supply in. How would i include the type_id in the criteria query.


just add:

Code:
criteriaTypes.add(Expression.eq("type_id", typeId)); //any other expressions can be used


you do not need to assign result of this call to anything. You will have what you need

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject: Re: Question on creating criteria
PostPosted: Tue Aug 16, 2005 7:32 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
Quote:
just add:

Code:
criteriaTypes.add(Expression.eq("type_id", typeId)); //any other expressions can be used


you do not need to assign result of this call to anything. You will have what you need


Sorry, I missed part with SQL
Actually, your code already provides you same result as SQL above.


Also you can write something like that:

Code:

Criteria criteriaValues = session.createCriteria(QualifierValues.class);
Criteria criteriaTypes = criteriaValues.createCriteria("qualifierTypes");

Criteria criteriaFunctions = session.createCriteria(Function.class)
add(Expression.eq("id", new Integer(arg_functionId)));
criteriaTypes.add(Expression.in("type_id", criteriaValues.list()));



But first one is faster

_________________
Vasyl Zhabko


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