-->
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.  [ 8 posts ] 
Author Message
 Post subject: need a help in sql( to hql)..
PostPosted: Tue Nov 07, 2006 4:03 am 
Newbie

Joined: Tue Feb 21, 2006 2:00 am
Posts: 14
Location: Seoul, Korea
I must make joined sql in hql.

below code success execute in sqlplus.

but, can't make hql.. didn't understand hql reference.

several modification all failed.

Code:
from table1 as sld1, table3 as sld3 WHERE sld1.serialNo = sld3.id.serialNo(+) and sld3.id.objectId(+) = 'KKK'


please show me above sql to hql.

thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 5:21 am 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
got the same question,

is there any way to outer join entities which are not related in mappings using HQL?

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 7:24 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 11:21 am
Posts: 42
No. Either add a relation to your mapping file or use Native-SQL.
Regards,
Georg

_________________
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 7:15 pm 
Newbie

Joined: Tue Feb 21, 2006 2:00 am
Posts: 14
Location: Seoul, Korea
due to my poor english, I don't exactly understand you two guys said.

In my example code, table1 and table3 all have mapping file.

just I can't make hql from native sql.

Hmm.. my mistake in example code.

success native sql(oralce) is like this..

Code:
select .. from table1 sld1, table3 sld3
where sld1.serial_no = sld3.serial_no(+)
and sld3.object_id(+) = 'KKK'


I make hql from above code like this..

Code:
from table1 as sld1, table3 as sld3 WHERE sld1.serialNo = sld3.id.serialNo(+) and sld3.id.objectId(+) = 'KKK'


hibernate hql reference can be understand by me..

serveral modification fails..

so, please someone show me correct hql.

thanks in advance..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 7:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Asssuming the mappings have the association between the two tables using the serialNo and the 'id' is renamed to something else as its reserved in HQL.
Something like the following
Code:

from table1 as sld1 left join sld1.table3 as sld3 WHERE sld3.idval.objectId = 'KKK' or sld3.idval.objectId is null


It is likely you will need to use a native query here but hopefully this gives you an idea.


Top
 Profile  
 
 Post subject: sorry, can't understand exactly..
PostPosted: Tue Nov 07, 2006 9:42 pm 
Newbie

Joined: Tue Feb 21, 2006 2:00 am
Posts: 14
Location: Seoul, Korea
Quote:
Asssuming the mappings have the association between the two tables using the serialNo and the 'id' is renamed to something else as its reserved in HQL.


I think what you said "Asssuming the mappings have the association between the two tables using the serialNo..." means they must have explicit association statement in their mapping files or others.

I just have mapping files contain their table schema only.
Primary key of table1 is serial_no, and table3 have serial_no and object_id.
So, table3 has composite key "id" contains serialNo and objectId.

If I need explict "join" statement or something in their mapping files to use "join" in hql.
That means I don't have primary(or base) knowledge about hibernate.

Hmm.. poor english and only one man( no other people around me interesting about hibernate). It takes long time to have practical skill even after used 9month!ㅡㅡ;

even I can't catch what you said " 'id' is renamed to something else..".

and your example code..
Code:
from table1 as sld1 left join sld1.table3 as sld3 WHERE sld3.idval.objectId = 'KKK' or sld3.idval.objectId is null


maybe incorrect. 'sld1.table3' what means? you mean like this?

Code:
from table1 as sld1 left join table3 as sld3 WHERE sld3.idval.objectId = 'KKK' or sld3.idval.objectId is null


sorry..as still newbie after nine month.. for can't understand what you said.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 08, 2006 2:51 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 11:21 am
Posts: 42
Add a mapping like this to your mapping file for table1:

Code:
<set inverse="true" lazy="true" name="table3Set">
   <key column="SERIAL_NO" />
   <one-to-many class="table1" />
</set>


Furthermore I assume the mapping for table3 looks like this:
Code:
...
<hibernate-mapping package="com.mycompany.mysoftware.mappings">
    <class name="table3" table="table3>
        <composite-id name="idval" class="table3PK">
            <key-property
                name="serialNo"
                column="SERIAL_NO"
                type="java.lang.Long"
                length="20"/>
            <key-property
                name="objectId"
                column="OBJECT_ID"
                type="string"
                length="10"/>
        </composite-id>
...


After restarting your application you can execute a HQL query like this:
from table1 as sld1
left join sld1.table3Set
where sld3.idval.objectId = 'KKK' or sld3.idval.objectId is null

idval is the name of the composite-id in table3
table3Set is the name of the association from table1 to table 3

Regards,
Georg

_________________
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25


Top
 Profile  
 
 Post subject: I clearly understand you.
PostPosted: Wed Nov 08, 2006 3:00 am 
Newbie

Joined: Tue Feb 21, 2006 2:00 am
Posts: 14
Location: Seoul, Korea
Georg!

You completly helped me understand that david wrote.

thank you very much.

It is very helpful!


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