Search code examples
mybatisibatisspring-mybatis

Exception with rownum in mybatis


Following is my sql query that is used in mybatis mapper xml.

<select id="getData"   fetchSize="30" resultType="java.util.HashMap" >
            select * from table
            where module='AB'
            and rownum < 15
</select>

I am getting below exception while using rownum :

 Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 130; columnNumber: 16; The content of elements must consist of well-formed character data or markup.

Below things I have tried:

ROWNUM&lt;=15  AND <![CDATA[ ROWNUM <= 15 ]]>

But still it is not working.


Solution

  • Try this:

    <select id="getData" fetchSize="30" resultType="java.util.HashMap" >
                select * from table
                where module='AB'
                <![CDATA[ AND ROWNUM <= 15 ]]>
    </select>
    

    or ROWNUM &lt;= 15 (with whitespaces after ROWNUM and before 15).