Tag Archives: Mybatis Error

MyBatis Error: Error building SqlSession [How to Solve]

MyBatis Error building SqlSession.

The error may exist in SQL Mapper Configuration

Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.ClassNotFoundException

In the configuration file:

<mappers>
    <mapper class="com/base/dao/UserMapper.xml"/>
</mappers>

written as:

<mappers>
    <mapper resource="com/base/dao/UserMapper.xml"/>
</mappers>

If you still can’t find it, you can configure pom.xml

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
</build>

[Solved] Mybatis Error: Invalid bound statement (not found)

Error reason: mapper file does not match

Check whether the mapper file is written incorrectly

Check the import configuration of mapper. Note that mapper cannot be imported across packages

Check whether the corresponding mapper file is generated in target/classes. If not, the solution is as follows

Add the following configuration to pom.xml, clean and recompile

</build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </resource>
    </resources>
</build>

How to Solve Mybatis Error: java.lang.UnsupportedOperationException

The error information is as follows:

Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.UnsupportedOperationException

Exception root: resulttype returns the element type in the collection, not the collection itself

The code is as follows:

    <!--Check detailed order information-->
    <resultMap id="orderDetailMap" type="com.alibaba.fastjson.JSONArray">
        <result column="order_code" property="orderCode"/>
        <result column="state" property="state"/>
        <result column="address" property="address"/>
        <result column="received_telephone" property="receivedTelephone"/>
        <result column="send_linkman" property="sendLinkman"/>
        <result column="send_telephone" property="sendTelephone"/>
        <result column="delivery_time" property="deliveryTime"/>
        <result column="delivery_time_quantum" property="deliveryTimeQuantum"/>
        <result column="greeting_card" property="greetingCard"/>
        <result column="show_pay_name" property="showPayName"/>
        <result column="pay_time" property="payTime"/>
        <result column="order_total_amount" property="orderTotalAmount"/>
        <result column="is_invoice" property="isInvoice"/>
        <result column="settled_amount" property="settledAmount"/>
        <result column="delivery_money" property="deliveryMoney"/>
        <collection property="goods" column="order_code"  ofType="com.alibaba.fastjson.JSONObject" javaType="List" select="findOrderChildDetail">
            <result column="item_sku_code" property="itemSkuCode"/>
            <result column="sku_title" property="skuTitle"/>
            <result column="sale_price" property="salePrice"/>
            <result column="buy_cnt" property="buyCnt"/>
            <result column="totalPrice" property="totalPrice"/>
        </collection>
    </resultMap>
    <select id="queryOrderDetail" parameterType="Map" resultMap="orderDetailMap">
        SELECT
            order_code,
            state,
            received_linkman,
            CONCAT(received_address_area,received_address_desc) AS 'address',
            received_telephone,
            send_linkman,
            send_telephone,
            delivery_time,
            delivery_time_quantum,
            greeting_card,
            show_pay_name,
            pay_time,
            order_total_amount,
            is_invoice,
            settled_amount,
            delivery_money
        FROM
            order_info
        WHERE
            account_code = #{accountCode}
        AND
            order_code = #{orderCode}
        LIMIT 1
    </select>

    <!--Check detailed order information-->
    <select id="findOrderChildDetail" parameterType="String" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
            item_sku_code ,
            sku_title ,
            sale_price ,
            buy_cnt ,
            sale_price *  buy_cnt AS totalPrice
        FROM
            order_detail
        WHERE
            order_code = #{orderCode}
    </select>
    

Error reason:

    <resultMap id="orderDetailMap" type="com.alibaba.fastjson.JSONArray">
    The JSONArray type in the error, modified to
    <resultMap id="orderDetailMap" type="com.alibaba.fastjson.JSONObject">

Note: the type here is the type used in the current development. If the object is used, check whether the type in the resultmap is a list or an object. If it is an associated subquery, modify it to an object