Search code examples
javasql-serveribatis

Error to retrieve data


My table:

CREATE TABLE [dbo].[R_ACADEMIE](
    [ID_ACADEMIE] [dbo].[IDENTIFIANT] NOT NULL,
    [LC_ACADEMIE_CODE] [dbo].[LIBELLE_COURT] NOT NULL,
    [LM_ACADEMIE_LIBELLE] [dbo].[LIBELLE_MOYEN] NOT NULL
) ON [PRIMARY]

My result map:

<resultMap class="business.bo.AcademieBO"
    id="AcademieBOResult">
    <result column="ID_ACADEMIE" jdbcType="NUMERIC"
        property="idAcademie" />
    <result column="LC_ACADEMIE_CODE" jdbcType="VARCHAR"
        property="lcAcademieCode" />
    <result column="LM_ACADEMIE_LIBELLE" jdbcType="VARCHAR"
        property="lmAcademieLibelle" />
</resultMap>

AcademiBO.java:

import java.io.Serializable;
import java.math.BigDecimal;

public class AcademieBO implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * <code>idCivilite</code> the idCivilite
     */
    private BigDecimal idAcademie;

    /**
     * <code>lcCivCode</code> the lcCivCode
     */
    private String lcAcademieCode;

    /**
     * <code>lmCivLibelle</code> the lmCivLibelle
     */
    private String lmAcademieLibelle;

    public BigDecimal getIdAcademie() {
        return idAcademie;
    }

    public void setIdAcademie(BigDecimal idAcademie) {
        this.idAcademie = idAcademie;
    }

    public String getLcAcademieCode() {
        return lcAcademieCode;
    }

    public void setLcAcademieCode(String lcAcademieCode) {
        this.lcAcademieCode = lcAcademieCode;
    }

    public String getLmAcademieLibelle() {
        return lmAcademieLibelle;
    }

    public void setLmAcademieLibelle(String lmAcademieLibelle) {
        this.lmAcademieLibelle = lmAcademieLibelle;
    }


}

dbo_ACADEMIE_SqlMap.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="dbo_ACADEMIE">
    <resultMap class="business.bo.AcademieBO"
        id="AcademieBOResult">
        <result column="ID_ACADEMIE" jdbcType="NUMERIC" property="idAcademie" />
        <result column="LC_ACADEMIE_CODE" jdbcType="VARCHAR" property="lcAcademieCode" />
        <result column="LM_ACADEMIE_LIBELLE" jdbcType="VARCHAR"
            property="lmAcademieLibelle" />
    </resultMap>

    <select id="listAll" resultMap="AcademieBOResult">
        select * from dbo.R_ACADEMIE
        ORDER BY ID_ACADEMIE ASC
    </select>

    <select id="selectByIdCivilite" resultMap="AcademieBOResult">
        select * from dbo.R_ACADEMIE where ID_ACADEMIE = #idAcademie:INTEGER#
    </select>
</sqlMap>

The error :

SqlMapClient operation; uncategorized SQLException for SQL [];
SQL state [null];
error code [0];
The error occurred in
dao/maps/dbo_ACADEMIE_SqlMap.xml.
The error occurred while applying a result map.
Check the dbo_ACADEMIE.AcademieBOResult. Check the result mapping for the 'idAcademie' property.
Cause: com.ibatis.sqlmap.client.SqlMapException: Error getting nested result map values for 'academie'.
Cause: java.sql.SQLException: Invalid column name ID_ACADEMIE.;
nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
The error occurred in dao/maps/dbo_ACADEMIE_SqlMap.xml.
The error occurred while applying a result map.
Check the dbo_ACADEMIE.AcademieBOResult.
Check the result mapping for the 'idAcademie' property.
Cause: com.ibatis.sqlmap.client.SqlMapException: Error getting nested result map values for 'academie'.
Cause: java.sql.SQLException: Invalid column name ID_ACADEMIE.


Solution

  • You cannot use select * in iBatis, you need to give all the column name in order iBatis to be able to map the correct column to the correct object property.

       <select id="listAll" resultMap="AcademieBOResult">
            select ID_ACADEMIE, LC_ACADEMIE_CODE, LM_ACADEMIE_LIBELLE from dbo.R_ACADEMIE
            ORDER BY ID_ACADEMIE ASC
        </select>
    

    Double check also your SQL request in a separate tool (SQL Developper) to be sure it works. I don't really understand your create table script : I'm not familiar with SQL Server and it seems strange to me the way you redefine the column name and the fact that there is no column types, maybe the issue lies here ...