-->
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.  [ 6 posts ] 
Author Message
 Post subject: HQL outer join with restriction
PostPosted: Tue Sep 27, 2005 10:54 pm 
Newbie

Joined: Tue Sep 20, 2005 5:14 pm
Posts: 8
I need to write an outer join query with a restriction on an inner table.
Written in sybase the query would look like this:

select I.*
from ITEM I left outer join BID B on I.ITEM_ID = B.ITEM_ID
where B.amount *= 10

How can this query be expressed in HQL?
Or does HQL follow strict ANSI standards that prohibit usage of inner table in any where clause conditons? If so is there a work around?

Thank you.

_________________
Stan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 11:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Hibernate3 adds a "WITH" clause to joins, which is what you want. Check the docs


Top
 Profile  
 
 Post subject: HQL "with" clause
PostPosted: Thu Sep 29, 2005 10:30 am 
Newbie

Joined: Tue Sep 20, 2005 5:14 pm
Posts: 8
Hi, Steve!

Thank you for reply. I found "with" keyword example on page 139 of Hibernate3 reference guide under section "15.3 Associations and joins".

I ran my query with it and got an error: unexpected token: with ...

Here is the detailed error message for my query:

=======================================
10:18:20,655 ERROR PARSER:35 - *** ERROR: line 1:137: unexpected token: with
org.hibernate.hql.ast.QuerySyntaxError: unexpected token: with near line 1, column 137 [select feed, feedinstance from com.csfb.fao.clr.model.FeedStatic as feed left outer join feed.feedInstances as feedinstance with feedinstance.mostRecent='Y']
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:215)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:421)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:824)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at Main.test5(Main.java:192)
at Main.main(Main.java:43)
Caused by: line 1:137: unexpected token: with
==========================================

I then proceeded to eliminate the "with" token, and the query ran just fine without this restriction! It correctly returned a combinaton of FeedStatic abd FeedInstance objects and I was able to process them.

Do you know why I am not able to utilize the "with" keyword? The doc has just one example on its usage. Is there anything else I might be missing?

Thank you.

_________________
Stan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
most likely you are not using a version of Hibernate that supports the WITH keyword :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 1:41 pm 
Newbie

Joined: Tue Sep 20, 2005 5:14 pm
Posts: 8
Steve,

We are using version 3.0.1, here is the Manifest file from Hibernate3.jar:

=============================
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.4.2-38 ("Apple Computer, Inc.")
Hibernate-Version: 3.0.1
=============================

Should we switch to a later version? I am not sure where to obtain the documentation on versions and features. Is there a release notes web page for Hibernate versions?

The reference guide describing "with" key word is for v3.1 beta:

http://docs.jboss.org/ejb3/app-server/H ... erence.pdf

Is this the first version supporting "with"?

Thank you.

_________________
Stan


Top
 Profile  
 
 Post subject: Re:
PostPosted: Tue Jul 13, 2010 6:17 am 
Newbie

Joined: Fri Jul 02, 2010 6:27 am
Posts: 5
stanlevin wrote:
... We are using version 3.0.1 ...
Note that it is not enough to use H3, you must also set the correct Query Translator Factory in the hibernate.properties file.
Code:
#hibernate.query.factory_class org.hibernate.hql.classic.ClassicQueryTranslatorFactory
hibernate.query.factory_class org.hibernate.hql.ast.ASTQueryTranslatorFactory
I had the same problem here: https://forum.hibernate.org/viewtopic.php?f=1&t=1005758&start=0


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