Question

i'm trying to insert multiple objects into a table with ibatis,i suppose the class cast exception get cast when the HasMap parameter is passed to dao mapper method , because breakpoints don't get hit and the insert query doesn't get logged . I've tried to pass a list but got the same exception . Below i've posted the code , at the moment i'm completly clueless. what's wrong the mapping ?

xml mapping :

    <insert id="insert" parameterType="java.util.HashMap">
INSERT INTO [ANTICIPI_F]
       ([ID],[ID_BATCH],[ID_FASCICOLO],[ABI],[CED]
       ,[ORIGINE],[TIPO],[IMPORTO],[PEZZI]
       ,[NUMERO_FATTURA],[PAGINA_FATTURA],[TRASMESSO]
       ,[NUMERO_FATTURA_ELAB],[DATA_CREAZIONE])
VALUES
   <foreach collection="anticipi" item="item" separator=",">
      (  #{item.ID} ,#{item.ID_BATCH},#{item.ID_FASCICOLO}
       ,#{item.ABI},#{item.CED},#{item.ORIGINE}
       ,#{item.TIPO},#{item.IMPORTO},#{item.PEZZI}
       ,#{item.NUMERO_FATTURA},#{item.PAGINA_FATTURA}
       ,#{item.TRASMESSO},#{item.NUMERO_FATTURA_ELAB}
       ,#{item.DATA_CREAZIONE})
   </foreach> 
</insert>

this is the model :

    public class AnticipoF implements Serializable{


    /**
     * 
     */
    private static final long serialVersionUID = 6679856006862546933L;
    private Integer ID;
    private Integer ID_BATCH;
    private String ID_FASCICOLO;
    private Integer ABI;
    private Integer CED;
    private String ORIGINE;
    private String TIPO;
    private Double IMPORTO;
    private Integer PEZZI;
    private String NUMERO_FATTURA;
    private Integer PAGINA_FATTURA;
    private Integer TRASMESSO;
    private String NUMERO_FATTURA_ELAB;
    private Date DATA_CREAZIONE;


//... getters and setters       
  //...equals and hashcode}

the mapped method signature :

public void insertAnticipiFatturaKofax(HashMap<String,Object> anticipiFattureKofax) throws SQLException;

the hash map :

List<AnticipoFatturaKofax> anticipiFattureKofax = new ArrayList<AnticipoFatturaKofax>();
HashMap<String,Object> anticipi = new HashMap<String, Object>();
anticipi.put("anticipi", anticipiFattureKofax);

the call :

anticipiFattureKofaxMapper.insertAnticipiFatturaKofax(anticipi);
Was it helpful?

Solution

The problem wasn't in ibatis but in a logging class injected by spring aop. Anyway , since i've spent a lot of time on this (i'm a beginner in ibatis and spring) , the correct mapping of the insert command , for sql server older than 2008 , is :

INSERT INTO [ANTICIPI_FATTURE_KOFAX]
       ([ID],[ID_BATCH],[ID_FASCICOLO],[ABI],[CED]
       ,[ORIGINE],[TIPO],[IMPORTO],[PEZZI]
       ,[NUMERO_FATTURA],[PAGINA_FATTURA],[TRASMESSO]
       ,[NUMERO_FATTURA_ELAB],[DATA_CREAZIONE])
   <foreach collection="anticipi" item="item" open="SELECT" separator="UNION ALL SELECT">
      #{item.ID} ,#{item.ID_BATCH},#{item.ID_FASCICOLO}
       ,#{item.ABI},#{item.CED},#{item.ORIGINE}
       ,#{item.TIPO},#{item.IMPORTO},#{item.PEZZI}
       ,#{item.NUMERO_FATTURA},#{item.PAGINA_FATTURA}
       ,#{item.TRASMESSO},#{item.NUMERO_FATTURA_ELAB}
       ,#{item.DATA_CREAZIONE}
   </foreach> 
</insert>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top