mybatis/old-google-code-issues

Mybatis 3.2.0 can not handle the space in SQL,but Mybatis 3.1.1 can do this

Closed this issue · 0 comments

when i use Activiti(5.12) and MyBatis(3.2.0),the application show some errors:

    Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id ' in 'class org.activiti.engine.impl.persistence.entity.UserEntity'

I read the source code of the activiti,and find that this is a spaces in the 
User.xml,like this:

    <insert id="insertUser"     
    parameterType="org.activiti.engine.impl.persistence.entity.UserEntity">
    insert into ${prefix}ACT_ID_USER (ID_, REV_, FIRST_, LAST_, EMAIL_, PWD_)
    values (
      #{id ,jdbcType=VARCHAR},
      1,
      #{firstName ,jdbcType=VARCHAR},
      #{lastName ,jdbcType=VARCHAR},
      #{email ,jdbcType=VARCHAR},
      #{password ,jdbcType=VARCHAR}
    )
  </insert>
then i read the documentation,it has not specifically  the space.so i change 
the Mybatis Version.It is OK.

  I read the source code of Mybatis,,and find the Mybatis(3.2.0) do not handle the space in SQL.but Mybatis(3.1.1) do it using the StringTokenizer(content, ", \n\r\t").The position In the "org.apache.ibatis.builder.SqlSourceBuilder.java".the method is "private Map<String, String> parseParameterMapping(String content) ".

  the source code in  Mybatis 3.2.0:
      try {
        return ParameterExpressionParser.parse(content);
      } catch (BuilderException ex) {
        throw ex;
      } catch (Exception ex) {
        throw new BuilderException("Parsing error was found in mapping #{" + content + "}.  Check syntax #{property|(expression), var1=value1, var2=value2, ...} ", ex);
      }

  the source code in  Mybatis 3.1.1:
      Map<String, String> map = new HashMap<String, String>();
      StringTokenizer parameterMappingParts = new StringTokenizer(content, ", \n\r\t");
      String propertyWithJdbcType = parameterMappingParts.nextToken();
      String property = extractPropertyName(propertyWithJdbcType);
      map.put("property", property);

I think that Mybatis should handle the space,sometimes, we make the code 
beautiful, may add some space,at the same time need the result fo the 
application correct!

Original issue reported on code.google.com by zofut...@163.com on 16 Apr 2013 at 4:13