You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by c....@ads.it on 2008/02/12 19:06:42 UTC

Re: discriminator and submap

> Niels Beekman
> Sat, 04 Nov 2006 03:35:52 -0800
> If only if/else behaviour is required, why not create an additional 
> column? Something like:

[...]

Hi all
Following the Niels' suggestion I wrote the map and query (see below)
A column TIPO_RIGA_ID of the table IDENTIFICATORI_VALORE is nullable.
Only when it's NOT null then we have to load other data (i.e. when the 
TIPO_RIGA_ID column is null no other data shold be loaded).
An additional column DI_TIPO_RIGA is created on the fly along with the 
corresponding discriminator.
The discriminator holds 1 iff the TIPO_RIGA_ID is not null, otherwise it 
holds 0.

The problem (see the top of the exception stack below) arises when the 
TIPO_RIGA_ID column is null.
=> the nullity of TIPO_RIGA_ID is the cause of the 
IllegalArgumentException
This is can be easily proved by removing (or readding) the 

                or IDENTIFICATORI_VALORE.TIPO_RIGA_ID is null

selection clause from (to) the query.
Please note that the whole SQL query (complete of rows with null 
ID_TIPO_RIGA) runs successfully (i.e. the problem is on the iBatis side).

The DB is Oracle 8.x. Please note that the query relies on 
shortcircuiting.
I suspect that iBatis tries to perform 

                <result property="idTipoRiga" column="TIPO_RIGA_ID" 
jdbcType="NUMERIC" javaType="int"/>

of the mapEspressioneValoriTipoRigaMulti (sub) result map that should be 
instead excluded by the 0 value of the discriminator.
I have no else branch here (no data to be loaded when the discriminator 
holds 0).

Might the lack of the "else" (zeroed value) branch be the problem?
Any suggestion?



Query

        <select id="selectEspressioneValoriMulti" 
resultMap="mapEspressioneValoriTipoRigaMulti">
                select VALORE_ID
                         , FORMULA_ID
                         , IDENTIFICATORI_VALORE.TIPO_RIGA_ID
                         , TESTO
                        ,  decode( IDENTIFICATORI_VALORE.TIPO_RIGA_ID, 
null, 0, 1) as DI_TIPO_RIGA 
                from IDENTIFICATORI_VALORE
                   , TIPI_DATO_RIGA
                where IDENTIFICATORI_VALORE.TIPO_RIGA_ID is not null
                and   IDENTIFICATORI_VALORE.TIPO_RIGA_ID = 
TIPI_DATO_RIGA.TIPO_RIGA_ID
                and  FORMULA_ID not in 
                (
                        select  FORMULA_ID
                        from    IDENTIFICATORI_FORMULA
                        where   NORMATIVA_ID is null
                )
                and TIPI_DATO_RIGA.TIPO_ELEMENTO_ID in 
                (
                        select  TIPO_DATO_ID
                        from    TIPI_DATO_ELEMENTO
                )
                or IDENTIFICATORI_VALORE.TIPO_RIGA_ID is null
        </select> 


Map

        <resultMap id="mapEspressioneValoriMulti" 
class="it.finmatica.gpj.ec.istruzioni.EspressioneStruct">
                <result property="id" column="VALORE_ID" 
jdbcType="NUMERIC" javaType="int"/>
                <result property="idIdentificatore" 
select="Gpj.selectIdIdentificatore" column="FORMULA_ID" javaType="int"/>
                <result property="idPeriodoNormativo" 
select="Gpj.selectIdPeriodoNormativo" column="FORMULA_ID" javaType="int"/>
                <discriminator column="DI_TIPO_RIGA" jdbcType="NUMERIC" 
javaType="int">
                  <subMap value="1" 
resultMap="mapEspressioneValoriTipoRigaMulti" />
                </discriminator>
        </resultMap>
        <resultMap id="mapEspressioneValoriTipoRigaMulti" 
class="it.finmatica.gpj.ec.istruzioni.EspressioneStruct" 
extends="mapEspressioneValoriMulti">
                <result property="idTipoRiga" column="TIPO_RIGA_ID" 
jdbcType="NUMERIC" javaType="int"/>
                <result property="nome" select="Gpj.selectNomeCampo" 
column="TIPO_RIGA_ID" javaType="java.lang.String"/> 
                <result property="testo" column="TESTO" jdbcType="VARCHAR" 
javaType="java.lang.String"/>
        </resultMap>



Exception stack (top of the)

com.ibatis.common.jdbc.exception.NestedSQLException: 
--- The error occurred in 
it/finmatica/gpj/aa/frontedb/EspressioneFabbricaImpl.xml. 
--- The error occurred while applying a result map. 
--- Check the Gpj.mapEspressioneValoriTipoRigaMulti. 
--- The error happened while setting a property on the result object. 
--- Cause: com.ibatis.common.exception.NestedRuntimeException: Error 
setting properties of 
'it.finmatica.gpj.ec.istruzioni.EspressioneStruct@77e024a'.  Cause: 
java.lang.IllegalArgumentException
Caused by: java.lang.IllegalArgumentException
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error 
setting properties of 
'it.finmatica.gpj.ec.istruzioni.EspressioneStruct@77e024a'.  Cause: 
java.lang.IllegalArgumentException
Caused by: java.lang.IllegalArgumentException
        at 
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(
GeneralStatement.java:188)
        at 
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(
GeneralStatement.java:123)


Trace of instructions (last 2 statements)

DEBUG [main] - {pstm-100006} PreparedStatement:    select 
IDENTIFICATORE_ID   from IDENTIFICATORI_FORMULA   where FORMULA_ID = ? 
DEBUG [main] - {pstm-100006} Parameters: [470]
DEBUG [main] - {pstm-100006} Types: [java.math.BigDecimal]
DEBUG [main] - {pstm-100008} PreparedStatement:    select NORMATIVA_ID 
from IDENTIFICATORI_FORMULA   where FORMULA_ID = ?