-->
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.  [ 3 posts ] 
Author Message
 Post subject: native SQL and WHERE clause -> sql error
PostPosted: Mon Dec 05, 2005 10:38 am 
Newbie

Joined: Mon Dec 05, 2005 10:25 am
Posts: 16
Oracle cannot use aliases in where clause, but HQL generate it.

EXAMPLE FROM HIBERNATE-REFERENCE IS NOT OK
Code:
String sql = "select cat.originalId as {cat.id}, " +
"cat.mateid as {cat.mate}, cat.sex as {cat.sex}, " +
"cat.weight*10 as {cat.weight}, cat.name as {cat.name} " +
"from cat_log cat where {cat.mate} = :catId"

List loggedCats = sess.createSQLQuery(sql)
.addEntity("cat", Cat.class)
.setLong("catId", catId)
.list();


Hibernate version: 3.0.5



Code between sessionFactory.openSession() and session.close():
Code:
   SQLQuery sq=session.createSQLQuery("Select a.algoritmus_id as {a.id}, a.algoritmus as {a.description} From MBO_algoritmus where {a.description} like ?");
         sq.setString(0,"%a%");
         sq.addEntity("a",Algorithm.class);
         sq.list();



Name and version of the database you are using: Oracle, version: Oracle9i Enterprise Edition Release 9.2.0.1.0

The generated SQL (show_sql=true):
Hibernate: Select a.algoritmus_id as Algoritmus1_0_, a.algoritmus as algoritmus0_0_ From MBO_algoritmus where algoritmus0_0_ like ?
WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 904, SQLState: 42000
ERROR [org.hibernate.util.JDBCExceptionReporter] - ORA-00904: "ALGORITMUS0_0_": invalid identifier



[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 12:30 am 
Newbie

Joined: Fri Dec 02, 2005 8:10 am
Posts: 8
Your from clause is not providing the alias "a" for the table name


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 3:34 am 
Newbie

Joined: Mon Dec 05, 2005 10:25 am
Posts: 16
With this (alias can be 'a' or '{a}') the error is the same.
Bad (the same) SQL is generated.

Code:
session.createSQLQuery(
"Select a.algoritmus_id as {a.id}, a.algoritmus as {a.description} From MBO_algoritmus {a} where {a.description} like ?");
...


Oracle cannot use aliases in where. You cannot use:
Code:
select a.name as alias from tableName a where alias='oracle';


But Hibernate create the select from code upper.


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