ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Randy Layman" <Randy.Lay...@vocalocity.com>
Subject RE: select list: expression values
Date Fri, 17 Nov 2006 14:39:24 GMT
 
    I think your problem might be that your SQL doesn't have a result
column ELEMENTO.  I believe you should change your SQL to:
select
TIPO_RIGA_ID, ELEMENTO - 1 AS ELEMENTO, NOME, TIPO_ELEMENTO_ID
from TIPI_DATO_RIGA
where tipo_dato_id = #id:INTEGER# 

so that the result set contains the correct column name in the meta
data.
 
    Randy
 


________________________________

From: c.zecca@ads.it [mailto:c.zecca@ads.it] 
Sent: Friday, November 17, 2006 9:34 AM
To: user-java@ibatis.apache.org
Subject: select list: expression values 



Hi all

The following SQL map and query

<resultMap id="mapTipoRiga"
class="it.finmatica.gpj.ec.tipidato.TipoCampoBean">
<result property="id" column="TIPO_RIGA_ID" jdbcType="NUMBER"
javaType="int"/>
<result property="ordinale" column="ELEMENTO" jdbcType="NUMBER"
javaType="int"/>
<result property="nome" column="NOME"
typeHandler="it.finmatica.gpj.aa.frontebd.NomeTypeHandlerCallback"/>
<result property="idTipoOrizzontale" column="TIPO_ELEMENTO_ID"
jdbcType="NUMBER" javaType="int"/>
</resultMap>
    
<select id="selectTipoRiga" resultMap="mapTipoRiga">
select
TIPO_RIGA_ID, ELEMENTO - 1, NOME, TIPO_ELEMENTO_ID
from TIPI_DATO_RIGA
where tipo_dato_id = #id:INTEGER# 
</select>    


raises the following exception



	DEBUG [main] - {pstm-100001} PreparedStatement:    select
TIPO_RIGA_ID, ELEMENTO - 1, NOME, TIPO_ELEMENTO_ID   from TIPI_DATO_RIGA
where tipo_dato_id = ?   
	DEBUG [main] - {pstm-100001} Parameters: [21]
	DEBUG [main] - {pstm-100001} Types: [java.lang.Integer]
	com.ibatis.common.jdbc.exception.NestedSQLException:   
	--- The error occurred in
it/finmatica/gpj/aa/frontebd/TipoRiga.xml.  
	--- The error occurred while applying a result map.  
	--- Check the GPJ.mapTipoRiga.  
	--- Check the result mapping for the 'ordinale' property.  
	--- Cause: java.sql.SQLException: Invalid colum name
	Caused by: java.sql.SQLException: Invalid colum name
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
WithCallback(GeneralStatement.java:185)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
ForList(GeneralStatement.java:123)



I have to load an 1-based index (stored in the ELEMENTO column) to
transform it into a 0-based Java index. I want to avoid to write a type
handler, thus i thought to use an expression as part of a select list
<http://www.firstsql.com/tutor3.htm#op> 

select ELEMENTO - 1

Please note that the query above is correct and is successfully run from
PL/SQL developer.

Replacing the "ELEMENTO - 1" expression with the "ELEMENTO" column
"works out" the problem but loades 1-based indexes. :(

Is there anything wrong?
Shall I write a type handler? (I cannot change the ordinale property of
the TipoCampoBean)

Regards

Mime
View raw message