Does any one knows how to obtain a max() on a string column?
The query I wanto to execute:
Code:
select MAX(TO_NUMBER(DOCNUM)) FROM HELAS.ONL_HEA_IN
the column (docnum) is a string, if I query the max value of this column using HQL:
Code:
HibernateTemplate ht = new HibernateTemplate(this.sessionFactory);
List maxDocNun = ht.find("select max(hin.Id.Docnum) from OnlHeaIn hin");
it returns tha MAX() of a string column, but I want to get the maximum numeric value of this column.
I tried to CAST(), but it does not work on a select statement:
Code:
ht.find("select max(cast(hin.Id.Docnum as integer)) from OnlHeaIn hin")
Quote:
Exception in thread "main" java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.AggregateNode
\-[AGGREGATE] AggregateNode: 'max'
\-[METHOD_CALL] MethodNode: '('
+-[METHOD_NAME] IdentNode: 'cast' {originalText=cast}
\-[EXPR_LIST] SqlNode: 'exprList'
+-[DOT] DotNode: 'onlheain0_.DOCNUM' {propertyName=Docnum,dereferenceType=4,propertyPath=Id.Docnum,path=hin.Id.Docnum,tableAlias=onlheain0_,className=br.seal.hibernate.vo.OnlHeaIn,classAlias=hin}
| +-[DOT] DotNode: 'onlheain0_.DOCNUM' {propertyName=Docnum,dereferenceType=2,propertyPath=Id.Docnum,path=hin.Id,tableAlias=onlheain0_,className=br.seal.hibernate.vo.OnlHeaIn,classAlias=hin}
| | +-[ALIAS_REF] IdentNode: '(onlheain0_.FILENAME, onlheain0_.DOCNUM, onlheain0_.STAT, onlheain0_.LAGER)' {alias=hin, className=br.seal.hibernate.vo.OnlHeaIn, tableAlias=onlheain0_}
| | \-[IDENT] IdentNode: 'Id' {originalText=Id}
| \-[IDENT] IdentNode: 'Docnum' {originalText=Docnum}
\-[IDENT] IdentNode: 'integer' {originalText=integer}
Hibernate version: 3.1Spring version: 1.2.7 database: Oracle 9iMapping documents:Quote:
<hibernate-mapping package="br.seal.hibernate.vo">
<class name="OnlHeaIn" table="HELAS.ONL_HEA_IN">
<composite-id class="OnlHeaInPK" name="Id">
<key-property column="FILENAME" name="Filename"
type="string" />
<key-property column="DOCNUM" name="Docnum" type="string" />
<key-property column="STAT" name="Stat" type="string" />
<key-property column="LAGER" name="Lager" type="string" />
</composite-id>
.........
</hibernate-mapping>
I accept any sugestions, HQL, Criteria, direct SQL,...
thanks