-->
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: SQL to HQL
PostPosted: Tue Sep 05, 2006 5:36 am 
Newbie

Joined: Mon Sep 04, 2006 10:45 am
Posts: 3
I have an SQL query and i want to convert it into a HQL query:

SELECT MESSAGES.MESSAGEID, MESSAGES.TYPE, MESSAGES.AREA, MESSAGES.FLOW, MESSAGES.OTHERFLOWINFO,
MESSAGES.DATECREATED, MESSAGES.DATELASTUPDATED, MESSAGES.CONTEXT, MESSAGES.STATUS, MESSAGES.PARENT,
PROBTRACKING.USERID
FROM MESSAGES
LEFT OUTER JOIN PROBTRACKING
ON MESSAGES.MESSAGEID = PROBTRACKING.MESSAGEID
AND PROBTRACKING.PROBLEMSTATUS = 'Unresolved'

Can this be done, i don't want to use create SQL query for this as i have filters set up, Struggling a lot with the syntax!

Any help is much appreciated,

Thanks


Top
 Profile  
 
 Post subject: Re: SQL to HQL
PostPosted: Tue Sep 05, 2006 9:33 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
new_nf wrote:
I have an SQL query and i want to convert it into a HQL query:

SELECT MESSAGES.MESSAGEID, MESSAGES.TYPE, MESSAGES.AREA, MESSAGES.FLOW, MESSAGES.OTHERFLOWINFO,
MESSAGES.DATECREATED, MESSAGES.DATELASTUPDATED, MESSAGES.CONTEXT, MESSAGES.STATUS, MESSAGES.PARENT,
PROBTRACKING.USERID
FROM MESSAGES
LEFT OUTER JOIN PROBTRACKING
ON MESSAGES.MESSAGEID = PROBTRACKING.MESSAGEID
AND PROBTRACKING.PROBLEMSTATUS = 'Unresolved'


Code:
from Messages m where m.probtracking.problemstatus='Unresolved'


Assuming messages<>probtracking is many-to-one.

Can you show the mappings?

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Fri Sep 08, 2006 3:29 am 
Newbie

Joined: Mon Sep 04, 2006 10:45 am
Posts: 3
Thanks for the help!

Unfortunately i am still lost.

In the messages table there are unique message id's

in the problem tracking table there are many problems which may be linked to the one message id but only one message id will have prob status = 'Unresolved'

My hibernate layer has no foreign keys set up, i was hoping to jus write a query like the one shown in SQL which produces the correct results!

Any help muchly appreciated!

Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 2:27 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
have you looked at
[url]
http://www.hibernate.org/hib_docs/v3/re ... references[/url]

i was thinking something like

session..createSQLQuery(sql)
.addEntity("msgs", Messages.class)

_________________
Don't forget to rate


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.