-->
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: Help with Native SQL query execution
PostPosted: Wed Aug 03, 2005 11:58 am 
Newbie

Joined: Wed Aug 03, 2005 11:34 am
Posts: 3
Hibernate version: 3

Code between sessionFactory.openSession() and session.close():
Code:
String query = "SELECT {t.*} FROM TRANSLATION {t}, RESOURCE_KEY {rk} WHERE {t}.LOCALE_ID = '3' AND {t}.KEY_ID = {rk}.id";
SQLQuery sqlQuery = session.createSQLQuery(query);
sqlQuery.addEntity("t", Translation.class);
sqlQuery.addEntity("rk", ResourceKey.class);
sqlQuery.list();



Full stack trace of any exception that occurs:
[java] WARN - SQL Error: 17006, SQLState: null
[java] ERROR - Invalid column name


Name and version of the database you are using: Oracle 9i

The generated SQL (show_sql=true):
Code:
SELECT t.ID as ID0_, t.KEY_ID as KEY2_3_0_, t.LOCALE_ID as LOCALE3_3_0_, t.REVISION_DATE as REVISION4_3_0_, t.TRANSLATOR_ID as
TRANSLATOR5_3_0_, t.TRANSLATION_TEXT as TRANSLAT6_3_0_ FROM TRANSLATION t, RESOURCE_KEY rk WHERE t.LOCALE_ID = '3' AND t.KEY_ID = rk.id



Hi, apparently the problem disspears if i add to the SELECT the ResourceKey table. But this is not what i want, because i only need the Translation table fields. What im doing wrong?. And I need to use Native SQL because this is only a part of my SQL query that use UNION. Thanks for your help!

Bye!


Top
 Profile  
 
 Post subject: Native SQL
PostPosted: Wed Aug 03, 2005 12:41 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
look at #17.5 http://www.hibernate.org/hib_docs/v3/re ... rysql.html

I think that something like:
Code:

<sql-query name="translation">
    <return alias="t" class="Translation" />
    SELECT {t.*} FROM TRANSLATION {t}, RESOURCE_KEY RK WHERE {t}.LOCALE_ID = '3' AND {t}.KEY_ID = RK.id
</sql-query>


could work for you


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 1:52 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
Don't add the ResourceKey entity, and do not make it substitutible in the query.
Untested code...

String query = "SELECT {t.*} FROM TRANSLATION {t}, RESOURCE_KEY rk WHERE {t}.LOCALE_ID = '3' AND {t}.KEY_ID = rk.id";
SQLQuery sqlQuery = session.createSQLQuery(query);
sqlQuery.addEntity("t", Translation.class);
sqlQuery.list();

-Ana


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 7:25 am 
Newbie

Joined: Wed Aug 03, 2005 11:34 am
Posts: 3
anar wrote:
Don't add the ResourceKey entity, and do not make it substitutible in the query.
Untested code...

String query = "SELECT {t.*} FROM TRANSLATION {t}, RESOURCE_KEY rk WHERE {t}.LOCALE_ID = '3' AND {t}.KEY_ID = rk.id";
SQLQuery sqlQuery = session.createSQLQuery(query);
sqlQuery.addEntity("t", Translation.class);
sqlQuery.list();

-Ana


Thanks Ana! That works fine for me! I really try everything yesterday but it seems that i dont test this way. Thanks again.

Bye


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.