-->
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.  [ 9 posts ] 
Author Message
 Post subject: cirteria.createAlias and outer join, bug or not ?
PostPosted: Thu Sep 02, 2004 3:34 am 
Newbie

Joined: Wed Sep 01, 2004 11:41 am
Posts: 8
Hibernate version:2.1.4

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:Oracle9i

Debug level Hibernate log excerpt:

Hi,

If I create an alias on a criteria based on a bean (Bs) have a one-to-one association with another (Mx), there is not outer join generated in query

Code:
/**
*
* @hibernate.class  table="BS"
*
* @author eboudrant
*/
public class Bs implements Serializable {
   private Mx mx;
...
   /**
    * @hibernate.one-to-one
    *       class="com.bnpparibas.eqd.msl.eai.monitoring.Mx"
    */
   public Mx getMx() {
      return mx;
   }
   public void setMx(Mx mx) {
      this.mx = mx;
   }
...
}


Code:
...
Criteria criteria = session.createCriteria(Bs.class);
criteria.createAlias("mx", "Mx");
criteria.add(
Expression.or(
  Expression.in("status", bsStatuses.toArray()),
  Expression.in("mx.status", mxStatuses.toArray())
)
);
...
criteria.find();


Here the join SQL generated :

[code]
... this.ID=mx.MXID ...
[code]

If I remove the createAlias, the outer join is here. I have this SQL join :


[code]
... this.ID=[??].MXID (+) ...
[code]

(Alias is computed by hibernate like that : mx2_) so I was unable to do Expression.in("mx.status", mxStatuses.toArray()).

Is this a bug or am I missing somethig ?

Thx,
-emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 3:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Looks like correct behavior to me. I must be missing what your problem is...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 3:42 am 
Newbie

Joined: Wed Sep 01, 2004 11:41 am
Posts: 8
The problem is I want an alias (mx) and an outer join between Bs and Mx because I have a 0-1 association and I want all result from Bs even there is no Mx. Like this :

Code:
... this.ID=mx.MXID (+) ...


not like that :

Code:
... this.ID=mx.MXID ...


Is it possible ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 3:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
But you are trying to apply an IN to a column of the outer joined table! That turns it right back into an inner join!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 4:02 am 
Newbie

Joined: Wed Sep 01, 2004 11:41 am
Posts: 8
But theses two query are not the same:

Code:
             select mx.status, bs.status from bs, mx
             WHERE bs.id = mx.mxid
             AND (bs.status in ('error')
             OR mx.status in ('error'));


With this query I have 3 results (missing 2)

Code:
             select mx.status, bs.status from bs, mx
             WHERE bs.id = mx.mxid (+)
             AND (bs.status in ('error')
             OR mx.status in ('error'));



With this query I have 5 results ... the (+) is very important for my needs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 5:05 am 
Newbie

Joined: Wed Sep 01, 2004 11:41 am
Posts: 8
Quote:
But you are trying to apply an IN to a column of the outer joined table! That turns it right back into an inner join!


No I trying to apply an OR on two IN, one in Bs and one in Mx. I simpley want to have a outer join between Bs and Mx. When I create alias, required for OR, Hibernate does not generate the (+).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 5:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ok, fair enough. Use HQL, not possible in the Criteria API


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 5:12 am 
Newbie

Joined: Wed Sep 01, 2004 11:41 am
Posts: 8
Ah the answer I don't want to heard ;)

Can you explain why ... or does a need tu add a feature request in JIRA ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 10:13 am 
Newbie

Joined: Wed Mar 03, 2004 11:22 am
Posts: 12
I added a comment to issue: http://opensource2.atlassian.com/projec ... e/HHH-1137 but I'll post it here as well.

Having outer joins added to the Criteria API is very important for my application.

I currently build queries like:
select cat
from Cat cat left join cat.kittens kitten
where
cat.name like 'T%' or
kitten.age > 35;

This query works great with HQL, but there is no way to build this query using the Criteria API to my knowledge. Using the Criteria API, the join condition would be an inner join, and cats with no kittens would not be returned from even if their first name started with a "T".

I'd be interested to hear how other people deal with dynamically built queries that rely on outer joins? Are you building SQL/HQL manually? Is there a workaround or patch for the Criteria API that I am not aware of?

Jeremy Haile


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.