-->
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: Complex query(?) on many-to-many
PostPosted: Fri Jan 12, 2007 10:48 am 
Newbie

Joined: Wed Jan 04, 2006 5:33 am
Posts: 2
Hi all,

I've been banging my head against this problem for a couple of days and coming to the conclusion that there's something fundamentally wrong with my way of thinking and the query I'm trying to build.

To begin I'm using Hibernate 3.2.1 against Oracle 10 XE.

My project concerns cars with options on cars linked together using an association entity class, basically very similiar to the example in the reference manual; Employer<->EmploymentPeriods<->Employee. The mappings are two bidirectional one-to-many associations, again same as said example.

Following the paradigm of said example I would want to return all employees who have worked for certain employers. Querying on a single employer or firing an OR statement for certain employers works but I cant return employees who have worked for employer1 AND employer2.

Here's the criteria setup I'm working on

Criteria crit = session.createCriteria(Employee.class);
Criteria critEmpPers = crit.createCriteria("employmentPeriods");
Criteria critEmployer = critEmpPers .createCriteria("employer");
critEmployer.add(Restrictions.conjunction()
.add( Restrictions.idEq(new Long(1)))
.add( Restrictions.idEq(new Long(3))));

If I use the disjunction I get all employees who have worked for employers 1 or 3 but I can't get those that have worked for 1 and 3.

What am I missing, someone give me a kick plz!

Colin


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.