-->
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 1, 2  Next
Author Message
 Post subject: double inner join using Criteria.createAlias
PostPosted: Wed May 26, 2004 8:24 pm 
Newbie

Joined: Wed May 12, 2004 2:26 am
Posts: 2
Location: san francisco, ca
i'd like to accomplish something like the HQL:

from Cat cat
inner join cat.kittens as kittens0
inner join cat.kittens as kittens1
where kittens0.name = 'Fred'
and kittens1.name = 'Amy'

which would find cats that have at least two kittens, one named fred and another amy.

is this possible with the current criteria api? i've tried:

Criteria.createCriteria (Cat.class)
.createAlias ("kittens", "kittens0").add (Expression.eq ("name", "Fred"))
.createAlias ("kittens", "kittens1").add (Expression.eq ("name", "Amy"));

and judging from the debugging sql output, the criteria query overwrites the first association with the second, and i get only one inner join:

from Cat cat
inner join cat.kittens as kittens1
where kittens0.name = 'Fred'
and kittens1.name = 'Amy'

which of course fails at the database level for having no kittens0.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 6:46 am 
Newbie

Joined: Wed Jun 09, 2004 5:53 am
Posts: 6
I have the same problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 10:29 pm 
Newbie

Joined: Fri Aug 06, 2004 10:22 pm
Posts: 3
Location: Illinois
You might want to check out Expression.conjunction(). It implements AND clauses...Expression.disjunction() does ORs. I hope this helps. Here is a link to a post referencing a simmilar situation:

http://forum.hibernate.org/viewtopic.php?p=2186938

_________________
Michael Minella
Senior Consultant
Software Architects, Inc
SCJP, SCWCD, IBM OO/UML


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 10:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes, this is a limitation, you can't join the same association twice.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 11:00 pm 
Beginner
Beginner

Joined: Thu Aug 28, 2003 3:09 pm
Posts: 39
Location: Brazil
Hi Gavin,

do you have some idea when this limitation can be removed, if possible?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 11:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ah .. not in a real hurry, it is due to how OuterJoinLoader works. (Historically, the Criteria query API was hacked in on top of the code that was originally used just for outer join fetching, so there are some slightly wierd limitations that don't affect HQL.)

What I'm seeing is that Hibernate 3.1 will probably concentrate on enhancements to Criteria query API (and perhaps also to HQL), it is not our priority for Hibernate 3.0.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2005 1:43 pm 
Newbie

Joined: Fri Mar 25, 2005 1:16 pm
Posts: 13
gavin wrote:
Ah .. not in a real hurry, it is due to how OuterJoinLoader works. (Historically, the Criteria query API was hacked in on top of the code that was originally used just for outer join fetching, so there are some slightly wierd limitations that don't affect HQL.)

What I'm seeing is that Hibernate 3.1 will probably concentrate on enhancements to Criteria query API (and perhaps also to HQL), it is not our priority for Hibernate 3.0.


Do you think in 3.1 that the Criteria API will be able to do everything that is possible in HQL? When I first chose Hibernate for a project over a year ago, it was instead of OJB, which I had already used. However, the shortcomings of the Criteria API quickly restricted it usage, which I lament. It is much easier to build queries with optional filters using the Criteria API than by trying to do a bunch of string concatenation. I think it is also easier to maintain and change queries, and to visually check for correctness.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 8:00 am 
Newbie

Joined: Mon Sep 19, 2005 6:47 am
Posts: 1
Hi gavin!

I'm a bit sad that this known problem not seems to be knocked out in Hibernate 3.1 beta 3.
Especially, because i want to switch from OJB to Hibernate due to confusing, not really working OJB Aliases in complex Queries with long attribute paths over several foreign and inverse foreign keys.

I would really like to construct queries with Criteria in Hibernate, because of it's clear and consistent handling.

Do you know, if someone's working on this issue and if it will be implemented in the release 3.1?
If not, maybe i'll dig through the sources for fixing.

Thanx!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 7:06 pm 
Newbie

Joined: Tue Jul 20, 2004 2:40 pm
Posts: 9
Location: New York, NY
exkog wrote:

I would really like to construct queries with Criteria in Hibernate, because of it's clear and consistent handling.



I'm in the same situation you are in terms of wanting to construct Criteria queries programmatically, and I'm currently running up against this same issue (the 'duplicate association'). I'm trying to build a Criteria query programmatically based on a set of criteria values passed into a function. The function must look through these values and add the criteria as needed. The entity I am querying for contains other entities as properties, some of which contain entities themselves, etc.

This seems like a pretty severe limit on the functionality of Criteria queries. Am I correct in assuming that what has been said above means you can not do something like this? :

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 do realize that you can accomplish the same thing by doing the following:

Code:
theCrit.createCriteria( "Address" )
                .add( Restrictions.in( "zipcode", aZipCodeCollection ) )
                .add( Restrictions.in( "city", aCityNameCollection ) );


...however, if you are building a set of Criteria programmatically it is much more complicated to determine when it would be necessary to do this, especially when you are dealing with a large number of Criteria that may or may not affect a particular property (in this case, an object with multiple properties) within an entity.

I noticed a new JIRA was created a few weeks ago:

http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1048?page=all

...is this a fix for this particular issue?

IMO, once this issue and the lack of the ability for Criteria queries to use the second-level object cache (i.e., the lack of functionality equivilant to Query's iterate() ) are resolved, the Criteria API will officially be rocking! =)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 8:19 pm 
Newbie

Joined: Tue Jul 20, 2004 2:40 pm
Posts: 9
Location: New York, NY
xanadu310 wrote:

I noticed a new JIRA was created a few weeks ago:

http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1048?page=all

...is this a fix for this particular issue?



...ok, I read that incorrectly, it definitely is not about the issue I was referring to. =/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 6:02 pm 
Newbie

Joined: Tue Jul 20, 2004 2:40 pm
Posts: 9
Location: New York, NY
Correction, here is the JIRA for this issue:

http://opensource2.atlassian.com/projec ... se/HHH-879


Top
 Profile  
 
 Post subject: Is anybody thinking about this?
PostPosted: Mon Feb 27, 2006 8:45 pm 
Newbie

Joined: Wed Sep 15, 2004 8:11 pm
Posts: 5
This issue has been a thorn in my side on a project of mine since last summer, and has recently reared its head again to create an even bigger problem.

I CANNOT use HQL because of differences in performace between Criteria and HQL... specifically HQL ignores the maxFetchDepth paramenter, and created unsatisfactory performance for some of the operations we are attempting. Therefore I am reliant on Criteria.

I even spent some time going deep into the Hibernate code myself to try to fix the problem, but to no avail.

Can someone please tell me there is a plan to fix this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 8:38 am 
Beginner
Beginner

Joined: Mon Aug 02, 2004 1:08 pm
Posts: 42
gavin wrote:
What I'm seeing is that Hibernate 3.1 will probably concentrate on enhancements to Criteria query API (and perhaps also to HQL), it is not our priority for Hibernate 3.0.


As far as I can see, there was no progress on that. Is anything planned?


Top
 Profile  
 
 Post subject: double join to the same association..
PostPosted: Tue Sep 19, 2006 11:04 am 
Newbie

Joined: Thu Sep 23, 2004 2:35 pm
Posts: 5
Hello Hibernate team,

Was this problem ever addressed and/or fixed?

Is it now possible to create a second join on the same association?

Need it urgently.. Is there a work around?

Regards,

Dmitry.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 8:28 am 
Newbie

Joined: Fri Jun 23, 2006 9:56 am
Posts: 10
Any updates on this issue?

It seems it is still reproducible on Hibernate 3.1.3.


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 1, 2  Next

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.