MyBatis version

3.2.7

Database vendor and version

MySql 5.6

Test case or example project

In the doc http://www.mybatis.org/mybatis-3/sqlmap-xml.html#insert_update_and_delete

sql

This element can be used to define a reusable fragment of SQL code that can be included in other statements. It can be statically (during load phase) parametrized. Different property values can vary in include instances. For example:

<sql id="userColumns"> ${alias}.id,${alias}.username,${alias}.password </sql>

The SQL fragment can then be included in another statement, for example:

<select id="selectUsers" resultType="map">
  select
    <include refid="userColumns"><property name="alias" value="t1"/></include>,
    <include refid="userColumns"><property name="alias" value="t2"/></include>
  from some_table t1
    cross join some_table t2
</select>

but my code is

public Map<String,Object> getAllList(String sign) throws Exception {
      Map<String, String> map = new HashMap<String, String>();  
      map.put("field", "201608_monthdata_"+sign);  
      map.put("val","weekdata_"+"a349001");  
      Map<String,Object> m = (Map<String, Object>) dao.findForObject("HarvesterMapper.getAlllist", map);
      return m;
}
<sql id="sql1">
    FROM ems_originaldata.${fieldText}
</sql>

<select id="getAlllist" parameterType="hashmap" resultType="hashmap"> <!--  getAlllist-->
    SELECT MAX(receivetime) as lastTime FROM(
    SELECT MAX(receivetime) AS receivetime 
    <include refid="sql1">
        <property name="fieldText" value="field"/>
    </include>
    ) aa
</select>

the exception is
''' Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 126; columnNumber: 13; 元素类型为 "include" 的内容必须匹配 "EMPTY"。 at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:256) at org.apache.ibatis.parsing.XPathParser.(XPathParser.java:125) at org.apache.ibatis.builder.xml.XMLMapperBuilder.(XMLMapperBuilder.java:78) at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:462) ... 139 more '''

mybatis3.2.7 don't super this format?

in xml dtd is

<!ELEMENT property EMPTY>
<!ATTLIST property
name CDATA #REQUIRED
value CDATA #REQUIRED
>

<!-- Dynamic -->

<!ELEMENT include (property+)?>
<!ATTLIST include
refid CDATA #REQUIRED
>

Comment From: harawata

It was added in 3.3.0. See #652 . Not a bug.

Comment From: kazuki43zoo

@harawata ~~Not #652~~. Probably, #331 ?

Comment From: harawata

You're right ;D Tricked by the title.

Comment From: WesTwardBlu

know it

Comment From: simsicon

I don't get it, can we still use property in include element? is this usage deprecated? What's the alternative method?

Comment From: harawata

@simsicon , Yes, you can use it. The reporter simply tried to use it with 3.2.7 while the feature was aded in version 3.3.0.

Comment From: simsicon

@simsicon , Yes, you can use it. The reporter simply tried to use it with 3.2.7 while the feature was aded in version 3.3.0.

Thank you

But I am still having this issue with 3.4.6, mybatis-spring version is 1.3.2

Related stacktrace:

Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: org.xml.sax.SAXParseException; lineNumber: 443; columnNumber: 19; The content of element type "include" must match "EMPTY".
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:314) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1674) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1426) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]

Comment From: harawata

@simsicon , com.ibatis.common.xml.NodeletException does not exist in 3.4.6. Check if there is any older JAR (mybatis-2.x or ibatis-2.x) in your classpath.

Comment From: simsicon

@simsicon , com.ibatis.common.xml.NodeletException does not exist in 3.4.6. Check if there is any older JAR (mybatis-2.x or ibatis-2.x) in your classpath.

You're right, turned out the code has heavy dependencies on ibatis-2, I guess I have to give up using the include property feature. Thanks.