-->
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: HQL problem: Using select max(to_number(field)) from ...
PostPosted: Mon Dec 10, 2007 7:11 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 9:43 am
Posts: 30
Hallo forum,

when calling following nethod:
Code:
   public Integer retrieveHighestBatchImportNumberForCustomer(String customerCode) {
      Integer highestNumber = null;
      String queryString = "select max(to_number(h.batchNum)) from BatchImportHistory as h where h.licNum=?";
      List<Integer> resultList = getHibernateTemplate().find(queryString, customerCode);
      if (resultList != null && resultList.size() > 0 && resultList.get(0) != null) { // Last check is important as we use MAX(...) that might return <NULL>
         logger.info("Highest batch import number: "+resultList.get(0));
         highestNumber = resultList.get(0);
      }
      return highestNumber;
   }


I'm getting following error:
Code:
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.AggregateNode
\-[AGGREGATE] AggregateNode: 'max'
    \-[METHOD_CALL] MethodNode: '('
       +-[METHOD_NAME] IdentNode: 'to_number' {originalText=to_number}
       \-[EXPR_LIST] SqlNode: 'exprList'
          \-[DOT] DotNode: 'batchimpor0_.BATCH_NUM' {propertyName=batchNum,dereferenceType=4,propertyPath=batchNum,path=h.batchNum,tableAlias=batchimpor0_,className=de.ls.spwebonline.model.domain.BatchImportHistory,classAlias=h}
             +-[ALIAS_REF] IdentNode: 'batchimpor0_.ID' {alias=h, className=de.ls.spwebonline.model.domain.BatchImportHistory, tableAlias=batchimpor0_}
             \-[IDENT] IdentNode: 'batchNum' {originalText=batchNum}


has anybody any idea what I'm doing wrong?


The same statement executed as SQL has no problems:
Code:
select max(to_number(BATCH_NUM)) bn from BATCH_IMPORT_HISTORY model where model.LIC_NUM='ROLAND'


Many thanks in advance!

Giorgi


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 3:03 pm 
Newbie

Joined: Mon Oct 29, 2007 2:33 pm
Posts: 16
Location: Cambridge, MA
I think the problem is that to_number is not a Hibernate function. (You can put "extra" functions in where clauses of HQL, but that is a special case.) You could try a SQL CAST expression.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 12, 2007 1:00 pm 
Beginner
Beginner

Joined: Mon Nov 13, 2006 9:43 am
Posts: 30
You think right!

...cast(h.batchNum, integer)... is a solution of this problem.

Thank you very much!


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.