-->
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.  [ 24 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Mon Nov 27, 2006 1:11 pm 
Regular
Regular

Joined: Tue Sep 30, 2003 11:27 am
Posts: 60
Location: Columbus, OH, USA
Encountering it here too. Maybe if createCriteria() and createAlias() could be coded to avoid duplicating the aliases/association paths and just graft the criterion onto the existing paths?

All the other workarounds we've considered smell bad...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 8:57 am 
Newbie

Joined: Thu Jul 20, 2006 4:18 am
Posts: 2
Quote:
Code:
// Assume these are valid collections:
Collection aZipCodeCollection;
Collection aCityNameCollection;

Criteria theCrit = theSession.createCriteria( User.class );

theCrit.createCriteria( "address" )
                .add( Restrictions.in( "zipcode", aZipCodeCollection ) );

theCrit.createCriteria( "address" )
                .add( Restrictions.in( "city", aCityNameCollection ) );



I encountered the same issue but found a solution for my case at least. If your problem is the same as mine could you not just add an alias? i.e

Code:
// Assume these are valid collections:
Collection aZipCodeCollection;
Collection aCityNameCollection;

Criteria theCrit = theSession.createCriteria( User.class ).createAlias("address","add");

theCrit.add( Restrictions.in( "add.zipcode", aZipCodeCollection ) );

theCrit.add( Restrictions.in( "add.city", aCityNameCollection ) );


I found this solution on page 265 of "Hibernate in Action"


Top
 Profile  
 
 Post subject: I stumbled into the same problem
PostPosted: Tue Jan 08, 2008 6:52 am 
Newbie

Joined: Mon Jan 07, 2008 4:15 pm
Posts: 1
I really don't understand what Hibernate is complaining about.

What is the problem with the query?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 9:01 am 
Newbie

Joined: Tue Nov 20, 2007 12:15 pm
Posts: 10
the problem is that hibernate does not appear to support self-joins correctly, which means that Criteria queries cannot be used for a whole host of query types that require multiple self-joins, such as graph matching. i don't see why not, because the difference between joining a table to itself or to another table seems like a trivial implementation issue...

perhaps a developer could shed enough light on the code limitation preventing this feature so that one of us could implement a fix, or at least comment on the status of this bug?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 4:09 am 
Newbie

Joined: Sun Apr 20, 2008 8:11 pm
Posts: 10
[edit: double post]


Last edited by KarimO on Tue Aug 19, 2008 4:10 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 4:10 am 
Newbie

Joined: Sun Apr 20, 2008 8:11 pm
Posts: 10
Any update on that limitation ? We are also quite struck over here.

Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 2:38 pm 
Newbie

Joined: Tue Dec 30, 2008 10:11 am
Posts: 4
I though I was just doing something wrong until I came across this.

This seems to be such a fundamental issue and makes a many to one relationship almost pointless in any instance where you need to control which of the one you return based on the many (via criteria).

Just in case I am doing something silly though, say I have the following.

I have a table that maps A's to B's, so if A 1 maps to B 5, 6, 7, 8 and 9 I have

A | B
------
1 | 5
1 | 6
1 | 7
1 | 8
1 | 9

Currently using criteria I can return A where B is in (5, 6, 7, 8, 9) hence I can return A where any of my B's map to it.

However if I want only those where A maps to all the B's in my list I can't do it through a criteria since I would need a join/alias from A to B for each eq clause.

(Note - this is only a small part of a programatically built up criteria set that effectively implements a configurable search function. As such taking this case in isolation does not solve the issue, it has to be 'plugable' into a larger criteria set)


Top
 Profile  
 
 Post subject: Re: double inner join using Criteria.createAlias
PostPosted: Wed Jun 09, 2010 8:54 am 
Beginner
Beginner

Joined: Tue Jan 02, 2007 5:53 pm
Posts: 42
Location: Bergen, Norway
What is the status of this issue, it's over a year since last post.

Cheers,
Steinard.


Top
 Profile  
 
 Post subject: Re: double inner join using Criteria.createAlias
PostPosted: Thu May 30, 2013 12:13 pm 
Newbie

Joined: Mon Jun 15, 2009 5:45 am
Posts: 3
I have been running into this limitation many times the last decade so i figured
it would help others to know the only practical workaround i have found so far :
Just map the same association as many times as you need to join it

so Cat would get two collections : kittens0 and kittens1
then :
Code:
Criteria.createCriteria (Cat.class)
.createAlias ("kittens0", "kittens0").add (Expression.eq ("name", "Fred"))
.createAlias ("kittens1", "kittens1").add (Expression.eq ("name", "Amy"));

does work as intended.

It's but ugly, i know and does puts a limitation on how many time one may join the association
So maybe it could get patched into the criteria API in order to make it transparent to the user...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 24 posts ]  Go to page Previous  1, 2

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.