-->
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.  [ 9 posts ] 
Author Message
 Post subject: undefined alias: decode
PostPosted: Sun Nov 16, 2003 11:31 pm 
Newbie

Joined: Sun Nov 16, 2003 11:24 pm
Posts: 6
Location: Taiwan
I have added decode=decode to query.substitutions but it's not work
did I miss anything else?

could any one tell me how to use decode() function of oracle in hiberante query language? thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 3:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Decode is not supported as a function in the select clause.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 9:29 pm 
Newbie

Joined: Sun Nov 16, 2003 11:24 pm
Posts: 6
Location: Taiwan
Thank you, David.

so that I'm tring use createSQLQuery to solve this problem.

Code:
StringBuffer sb = new StringBuffer("select {nego}.stk_no as {nego.stkNo}, {equity}.stk_name as {equity.stkNo} ");
sb.append("from cbotctrad as {nego}, te.testmb as {equity} ");
sb.append("where {nego}.stk_no = {equity}.stk_no");
Query q = session.createSQLQuery(sb.toString(), new String[] {"nego", "equity"}
, new Class[] {Negotiation.class, Equity.class});


the sql statement is simple but got following errors

Code:
09:20:59,703 INFO [STDOUT] Hibernate: select nego.stk_no as stk_no0_, equity.stk_name as stk_no1_ from cbotctrad as nego, te.testmb as equity where nego.stk_no = equity.stk_no
09:20:59,781 WARN [JDBCExceptionReporter] SQL Error: 933, SQLState: 42000
09:20:59,781 ERROR [JDBCExceptionReporter] ORA-00933: SQL command not properly ended

09:20:59,797 WARN [JDBCExceptionReporter] SQL Error: 933, SQLState: 42000
09:20:59,797 ERROR [JDBCExceptionReporter] ORA-00933: SQL command not properly ended

09:20:59,797 ERROR [JDBCExceptionReporter] SQLException occurred
java.sql.SQLException: ORA-00933: SQL command not properly ended

I have no ideas......


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 1:55 am 
Newbie

Joined: Sun Nov 16, 2003 11:24 pm
Posts: 6
Location: Taiwan
I have tried on the formula attribute.
but it must select all colums otherwise error occurred.

mappings:
Code:
<property name="decodeTradeAmount" formula="decode(bs_type, 'B', -1*td_amt, 'S', td_amt)"/>


error:
Code:
net.sf.hibernate.QueryException: could not resolve property: decodeTradeAmount
at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:35)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 2:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Stick with the createSQLQuery() solution. Thats the Right Way to solve it. But note that createSQLQuery MUST return entities (it can't do projection).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 2:24 am 
Newbie

Joined: Sun Nov 16, 2003 11:24 pm
Posts: 6
Location: Taiwan
createSQLQuery() seems a little issue about composite-id


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 2:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ah yes, I understand that this is fixed in CVS.

Max?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 22, 2003 3:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes ?

What's da' problem ? ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 4:10 pm 
Newbie

Joined: Tue Oct 12, 2004 10:32 pm
Posts: 5
In Hibernate 3.1.2, if I put a space between decode and the open parenthesis, like so:
Code:
  <property name="txnTypeDesc"
      type="java.lang.String"
      formula="(DECODE (UPPER (MAINTYP_CD),
                  'A', 'Add',
                  'C', 'Change',
                  'D', 'Delete'
                 ))"
      insert="false"
      update="false"
    />

Hibernate translates it into the following SQL:
Code:
(this_.DECODE (UPPER (this_.MAINTYP_CD),                   'A', 'Add',                   'C', 'Change',                   'D', 'Delete'                  )) as formula10_0_

And it doesn't work because DECODE is not a column, it's a function.

If I remove the space it works as expected.


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