-->
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.  [ 2 posts ] 
Author Message
 Post subject: Incorrect alias resolution for Expression
PostPosted: Wed Jun 02, 2004 12:04 pm 
Beginner
Beginner

Joined: Mon Nov 24, 2003 5:39 am
Posts: 26
Location: France
Hello,

When I run this:

Code:
List traces = getSessionMAJA().createCriteria(TraceStatistiques.class).add( Expression.sql("lower({alias}.action) like upper(?)", "stat%", Hibernate.STRING) ).list();


The generated SQL resolves to:

Code:
select this.ACA_C_ID as ACA_C_ID0_, this.ACA_D_DATE as ACA_D_DATE0_, this.ACA_C_ID_AGENT as ACA_C_ID5_0_, this.ACA_A_NOM_AGENT as ACA_A_NO3_0_, this.ACA_A_ACTION as ACA_A_AC4_0_, this.ACA_N_SERVICE_AGENT as ACA_N_SE6_0_, this.ACA_A_TYPE_STAT as ACA_A_T14_0_ from ACT_AGENT this where lower(this.action) like upper(?)


which is invalid
Quote:
ORA-00904: "THIS"."ACTION": invalid identifier
)

However putting the column name directly in the lower() function, generates the right SQL:

Code:
List traces = getSessionMAJA().createCriteria(TraceStatistiques.class).add( Expression.sql("lower({alias}.ACA_A_ACTION) like upper(?)", "stat%", Hibernate.STRING) ).list();


which resolves correctly to:

Code:
select this.ACA_C_ID as ACA_C_ID0_, this.ACA_D_DATE as ACA_D_DATE0_, this.ACA_C_ID_AGENT as ACA_C_ID5_0_, this.ACA_A_NOM_AGENT as ACA_A_NO3_0_, this.ACA_A_ACTION as ACA_A_AC4_0_, this.ACA_N_SERVICE_AGENT as ACA_N_SE6_0_, this.ACA_A_TYPE_STAT as ACA_A_T14_0_ from ACT_AGENT this where lower(this.ACA_A_ACTION) like upper(?)


My question:

How can I avoid hardcoding the column name (ACA_A_ACTION) in my Hibernate query?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Don't use Expression.sql() if you don't want to use table and column names.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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