-->
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: subquery with non-child
PostPosted: Tue Mar 28, 2006 7:06 pm 
Newbie

Joined: Wed Mar 22, 2006 3:22 pm
Posts: 9
Hibernate version:
3.1
Mapping documents:
NA
Code between sessionFactory.openSession() and session.close():
NA
Full stack trace of any exception that occurs:
NA
Name and version of the database you are using:
NA
The generated SQL (show_sql=true):
NA
Debug level Hibernate log excerpt:
NA

First I cannot change the schema :(

I have 2 entities A and B both have a field called firstName. The entities are not associated in any way.

I want to create a subquery using CriteriaQuery and/or DetachedCriteria. I want A to be the subquery of B and B only to return instances where B.firstName is in the results of A.

I have tried the following with no success...

sub = DetachedCriteria.forClass(A.class);
sub.setProjection(Property.forName("firstName"));
sub.add(Restrictions.eq("firstName", "John Doe"));


crit = Session.createCriteriaQuery(B.class)
crit.add(Subquries.eq("firstName", sub));
crite.list();

this returns and empty list. I did verify that "John Doe" was in both tables.
------------------------------------------------------------

Also tried...

crit.add(Property.forname("firstName", sub));

Any ideas of what I am doing wrong?


Top
 Profile  
 
 Post subject: hql?
PostPosted: Tue Mar 28, 2006 7:20 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Could you just use HQL?
Something like
select a.name from A a,B b where
a.name = b.name and a.name= ?

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.