-1

Hi I am trying to insert a list of object through ibatis but i am getting an exception like org.apache.ibatis.mapping.SqlMapperException: The expression 'boxlist' evaluated to a null value.

<insert id="insertList" parameterType="java.util.List">
    INSERT INTO boxtable (
    size,length)
    VALUES
    <foreach item="box" collection="boxList" separator=",">
        (#{box.size},#{box.length})
    </foreach>
</insert>

My dao class is like

public void insert(List<box> boxList)
        throws SQLException {

    try {                            
        sqlSession = sqlSessionFactory.openSession(AUTO_COMMIT); 
        int status = sqlSession.insert("insertlist", boxList);
        logger.debug("status :: " + status);
        sqlSession.commit();
    } catch (Throwable ee) {
        logger.error("e", ee);
    sqlSession.rollback();
    } finally {
        sqlSession.close();
    }

}

Can anyone help me out???

NilsH
  • 13,705
  • 4
  • 41
  • 59
Parekh Shah
  • 69
  • 2
  • 5
  • 9

2 Answers2

1

If I remember it right you need to pass an object containing boxList property or you could pass a map containing the boxList key. For example

public class Wrapper {
    private List<box> boxList;
}


<insert id="insertList" parameterType="Wrapper">
    INSERT INTO boxtable (
    size,length)
    VALUES
    <foreach item="box" collection="boxList" separator=",">
        (#{box.size},#{box.length})
    </foreach>
</insert>
Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71
0

try using <isPropertyAvailable> before the <foreach> in your sql statement. Also you could try using the <iterate> but don't forget to append [] to ur boxlist (as in #boxlist[]#)

For more on dynamic sql statements in ibatis follow this link

pranky64
  • 437
  • 3
  • 18