-->
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.  [ 4 posts ] 
Author Message
 Post subject: Wierd stuff creating a query with many joins
PostPosted: Wed Feb 25, 2004 11:16 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Hi guys.
I'm builduing a complex query at runtime.

It looks like:

Code:
DEBUG [net.sf.hibernate.hql.QueryTranslator] - HQL: select count(distinct recipient) from com.nmt.msp.resource.CategoryRecipientResource as categoryRecipient  join categoryRecipient.recipient as recipient  join categoryRecipient.category as category0  join categoryRecipient.category as category1  where recipient.system =:my_system and category0 IN (:my_category0) and category1 IN (:my_category1) AND (recipient.deleted = 0)


The QueryTranslator makes it to:
Code:
DEBUG [net.sf.hibernate.hql.QueryTranslator] - SQL: select count(distinct recipientr1_.id) as x0_0_ from categoryrecipient categoryre0_ inner join recipient recipientr1_ on categoryre0_.recipientid=recipientr1_.id inner join category simplecate2_ on categoryre0_.categoryid=simplecate2_.id where (recipientr1_.systemid=? )and(simplecate2_.id IN(?))and(simplecate2_.id IN(?))AND((recipientr1_.deleted=0 ))


Note the where conditions:

Code:
where recipient.system =:my_system and category0 IN (:my_category0) and category1 IN (:my_category1) AND (recipient.deleted = 0)


Code:
where (recipientr1_.systemid=? )and(simplecate2_.id IN(?))and(simplecate2_.id IN(?))AND((recipientr1_.deleted=0 ))


The join on category0 has desappeared. The where clause mentions twice simplecate2_ .

What's wrong?

/Roberto.

Quote:
#Hibernate properties generated through Ant
#Wed Feb 25 15:57:49 CET 2004
hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
hibernate.jdbc.use_streams_for_binary=true
hibernate.show_sql=true
hibernate.use_outer_join=true
hibernate.jdbc.batch_size=0
hibernate.cache.use_query_cache=false


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 12:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I think you cannot do 2 joins on the same collection (same table). Try do do it in plain SQL and if successful raise a bug to JIRA.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 3:34 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
I found out that my query had not much sense. Anyway this query is accepted by mysql 4.0:

Code:
select count(distinct recipientr1_.id) as x0_0_ from categoryrecipient categoryre0_ inner join recipient recipientr1_ on categoryre0_.recipientid=recipientr1_.id inner join category simplecate1_ on categoryre0_.categoryid=simplecate1_.id inner join category simplecate2_ on categoryre0_.categoryid=simplecate2_.id where (simplecate1_.id IN(1))and(simplecate2_.id IN(2));


It uses two joins on the same table.
Should I report a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 7:04 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes please

_________________
Emmanuel


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