-->
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 query to hql
PostPosted: Thu Aug 17, 2006 10:31 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
Hello,

I'm trying to translate a sql query to hql query with join

here is my query :

SELECT element.* FROM element, used_table, used_field where used_table.name = 'product' and element.ref_table = used_table.id_table and used_field.data_type = 1 and element.ref_field = used_field.id_field

thx in advance !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 10:58 am 
Beginner
Beginner

Joined: Fri Jul 30, 2004 2:53 pm
Posts: 33
Location: Washington, DC
It depends on what your mapping looks like, but I think something like this should work:

Code:
from Element as e
    inner join e.table as t
    inner join e.field as f
where
    t.name = 'product' and
    f.data_type = 1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 11:03 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 3:37 am
Posts: 29
yes if found a similar version

createQuery("from ElementDb element join element.usedTable ut join element.usedField uf where ut.name = 'PRODUCT' and uf.dataType = 1")


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 11:09 am 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
Thinking in SQL doesn't help with Hibernate. You should use a object oriented approach.
Did you define the relation between your entities?
I can make a guess:

Code:
SELECT element FROM element join element.used_table ut join ut.used_field uf where ut.name = ? and uf.data_type = ?


defining the many-to-one relations between element and used_table and between used_table and used_field.

See chapter 5 and 14 for more info on how to do it.

_________________
--
Marco


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.