-->
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: subquery in subcriteria does not work
PostPosted: Fri Jul 08, 2005 7:22 am 
Newbie

Joined: Fri Jul 08, 2005 6:28 am
Posts: 4
(Hibernate version: 3.0.5)

I have some problems using a subquery, first it cannot be
used with a property of an associated entity:

Criteria criteria = session.createCriteria(A.class);
criteria.add(...);
DetachedCriteria subQuery = DetachedCriteria.forClass(B.class);
subQuery.setProjection(Property.forName("B-some").max());
criteria.createCriteria("A-to-B-FK")
.add(Property.forName("B-some").eq(subQuery));

This code runs into a ClassCastException:
in SubqueryExpression.toSqlString(), line 43:
final SessionImpl session = ( (CriteriaImpl) criteria ).getSession();

criteria is cast to CriteriaImpl, but is of type CriteriaImpl.Subcriteria

Now, this really is a bug, or is it?

Furthermore, the subquery itself seems not to allow associations.
If I use the subquery in the main criteria (for testing to avoid
the above error), a simple flat subquery works. But if I make
an association:

subQuery.createCriteria("B-to-C-FK").add(Restrictions.eq("C-some",..));

the subquery-SQL is generated without the C-table, and uses
an alias for the C-table that was never defined:

.. where .. and x = [now the subquery:]
(select .. from B b_alias where c_alias.some = ..)

If I execute the subQuery (DetachedCriteria) directly it works
correctly. So again, the problem seems to be with subqueries.

At the moment I get the impression that Criteria API is not
usable for somewhat more complex queries - mine has a
subquery, multiple joins in outer query and subquery, and
uses properties of the outer query within the subquery.

Any help is appreciated.


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.