-->
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: t3 join (t1, t2 ) on( t1.id=t3.id
PostPosted: Tue Sep 23, 2008 9:07 am 
Newbie

Joined: Tue Sep 23, 2008 8:54 am
Posts: 4
Hi
I am having problem in writing qry in hibernate i want to left join programinstance with other tables .

i have writen following qry in mysql . it is working .

this is thw qry

SELECT *
FROM users u
JOIN (
emaillogs e, contacts c
) ON ( u.usersId = e.usersId
AND c.usersId = u.usersId )
LEFT JOIN programinstance pi ON pi.programinstanceId = e.programinstanceId
ORDER BY `e`.`typeOfEmail` ASC

when i write same qry in createQuery it is giving syntax error near JOIN ( . un expected token " ("

thanks





Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

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:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2008 6:53 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
I am unfamiliar with that join notation.
I always specify one join at a time, i.e.:

Code:
SELECT *
FROM users u
inner JOIN emaillogs e ON u.usersId = e.usersId
inner join contacts c on c.usersId = u.usersId
LEFT JOIN programinstance pi ON pi.programinstanceId =  e.programinstanceId
ORDER BY `e`.`typeOfEmail` ASC

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 11:36 am 
Newbie

Joined: Tue Sep 23, 2008 8:54 am
Posts: 4
thanks for the query . query is fetching the desired result .
but i am using createQuery method to execute this query

i am getting followng exception
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1,

is it possible to give join in the createQuery method ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 1:09 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
It is.
What you are getting is some minor SQL error (probably those apostrophes?).

If you know how to send the generated SQL statements to a log (I explain how to do it here), you can copy that generated SQL statement and try to execute it on your database directly.

That will quickly tell you what the problem is.

_________________
Gonzalo Díaz


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.