MyBatis: Boolean Parameter: MyBatis is using Getter

ساخت وبلاگ

Vote count: 0

Subject: MyBatis: Boolean Paraeter: MyBatis is using Getter

Content:

Hello everyone,

I have been searching for a while for a solution to my nearly-simple MyBatis problem:


Given code (only the necessary parts):

mybatis-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <typeAliases> <!-- Model types. --> <typeAlias type="com.blockhaus2000.bh2k.portal.data.model.Navigation" alias="Navigation" /> <!-- ... more types ... ---> </typeAliases> <mappers> <mapper resource="mapper/NavigationDAO.xml" /> <!-- ... more mappers ... --> </mappers>
</configuration>

NavigationDAO.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.blockhaus2000.bh2k.portal.data.dao.NavigationDAO"> <resultMap type="Navigation" id="navigationResultMap"> <id property="id" column="navigationId" /> <result property="title" column="navigationTitle" /> <result property="order" column="navigationOrder" /> <result property="visible" column="navigationVisible" /> <discriminator javaType="String" column="resolve"> <case value="yes" resultMap="enhancedNavigationResultMap" /> </discriminator> </resultMap> <resultMap type="Navigation" id="enhancedNavigationResultMap" extends="navigationResultMap"> <collection property="navigationEntries" ofType="NavigationEntry"> <id property="navigationId" column="navigationId" /> <id property="pageId" column="pageId" /> <result property="title" column="navigationEntryTitle" /> <result property="order" column="navigationEntryOrder" /> <result property="visible" column="navigationEntryVisible" /> </collection> </resultMap> <!-- Methods from BaseDAO. --> <insert id="insert" parameterType="Navigation" useGeneratedKeys="true" keyProperty="id" keyColumn="navigationId"> <!-- SQL --> </insert> <insert id="save" parameterType="Navigation"> <!-- SQL --> </insert> <delete id="delete" parameterType="Navigation"> <!-- SQL --> </delete> <select id="exists" parameterType="Navigation" resultType="boolean"> <!-- SQL --> </select> <!-- Methods from UpdateableDAO. --> <update id="update" parameterType="Navigation"> <!-- SQL --> </update> <!-- Methods from NavigationDAO. --> <select id="findVisibleNavigations" parameterType="boolean" resultMap="navigationResultMap"> SELECT N.navigationId, N.navigationTitle, N.navigationOrder, N.navigationVisible, <if test="resolve"> NE.pageId, NE.navigationEntryTitle, NE.NavigationEntryOrder, NE.navigationEntryVisible, </if> IF ( #{resolve} = 'true', 'yes', 'no' ) AS resolve FROM Navigation AS N <if test="resolve"> INNER JOIN NavigationEntry AS NE ON N.navigationId = NE.navigationId </if> WHERE N.navigationVisible = TRUE <if test="resolve"> AND NE.navigationEntryVisible = TRUE AND NE.navigationEntryTitle IS NOT NULL </if> </select> <select id="findHiddenNavigations" parameterType="boolean" resultMap="navigationResultMap"> <!-- SQL --> </select> <select id="findNavigation" parameterType="Map" resultMap="navigationResultMap"> <!-- SQL --> </select>
</mapper>

NavigationDAO.java:

package com.blockhaus2000.bh2k.portal.data.dao;
import java.util.SortedSet;
import com.blockhaus2000.bh2k.portal.data.model.Navigation;
public interface NavigationDAO extends BaseDAO<Navigation>, UpdateableDAO<Navigation> { SortedSet<Navigation> findVisibleNavigations(final boolean resolve); SortedSet<Navigation> findHiddenNavigations(final boolean resolve); Navigation findNavigation(final int id, final boolean resolve);
}

BaseDAO.java:

package com.blockhaus2000.bh2k.portal.data.dao;
import com.blockhaus2000.bh2k.portal.data.model.BaseModel;
public interface BaseDAO<T extends BaseModel<T>> { int insert(final T obj); int save(final T obj); int delete(final T obj); boolean exists(final T obj);
}

UpdateableDAO.java:

package com.blockhaus2000.bh2k.portal.data.dao;
import com.blockhaus2000.bh2k.portal.data.model.BaseModel;
public interface UpdateableDAO<T extends BaseModel<T>> extends BaseDAO<T> { int update(final T obj);
}

Everything is starting correctly, but on an invocation of

NavigationDAO.findVisibleNavigations(true) // Or false.

the following Exception is thrown:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'resolve' in 'class java.lang.Boolean' at org.mybatis.(...) at org.apache.ibatis.(...) at com.blockhaus2000.bh2k.portal.data.test.NavigationDAOSpec.test findVisibleNavigations(NavigationDAOSpec.groovy:224)
Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'resolve' in 'class java.lang.Boolean' at org.apache.ibatis.(...) at org.mybatis.(...) ... 5 more

That said, the solution may be to change the "parameterType" to "Map" and replacing "resolve" with "param1". But that does not work either. Also, if I remove the

<if test="..."> ... </if>

it does execute correctly (except for the functionaility, of course).


I am happy about every single answer.

Thanks for your help Fabian

asked 3 mins ago

- - , .

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 337 تاريخ : جمعه 30 بهمن 1394 ساعت: 6:56