The moose likes Object Relational Mapping and the fly likes Problem in Criteria Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Problem in Criteria" Watch "Problem in Criteria" New topic
Author

Problem in Criteria

Paras Jain
Ranch Hand

Joined: Feb 26, 2005
Posts: 137
Hi,
I am new to the criteria queries. Previously I have worked on some basic HQL queries.
I am having a problem in writing a criteria query

Here is the structure of my class

class C{
A a;
B b;
}

I want to write a query like this
select * from C where a.id="somevalue" and b.id="somevalue"

I want to achieve it in single query.

Currently I am doing this
First I am writing two different criteria queries to fetch instances of a and b and then I say

Criteria criteria = DetachedCriteria.forClass(C.class)
.add(Restrictions.eq("a", a))
.add(Restrictions.eq("b", b));


My question is - Is there any better way to do that, like getting it in a single criteria?

Regards,
Paras


Paras Jain
SCJP 5.0
 
 
subject: Problem in Criteria
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture