Skip to content

Commit

Permalink
Fixes #135. Fix ClassClastException when there is a handler for
Browse files Browse the repository at this point in the history
Map.class.
  • Loading branch information
emacarron committed Jan 25, 2014
1 parent e269526 commit 4045a0a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.binding.BindingException;
import org.apache.ibatis.binding.MapperMethod.ParamMap;
import org.apache.ibatis.builder.BuilderException;
import org.apache.ibatis.builder.IncompleteElementException;
import org.apache.ibatis.builder.MapperBuilderAssistant;
Expand Down Expand Up @@ -338,7 +339,7 @@ private Class<?> getParameterType(Method method) {
if (parameterType == null) {
parameterType = parameterTypes[i];
} else {
parameterType = Map.class;
parameterType = ParamMap.class; // issue #135
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.io.Reader;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
Expand Down Expand Up @@ -50,7 +52,7 @@ public static void setUp() throws Exception {
}

@Test
public void shouldGetAUser() {
public void shouldGetAUserFromAnnotation() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
Mapper mapper = sqlSession.getMapper(Mapper.class);
Expand All @@ -61,4 +63,19 @@ public void shouldGetAUser() {
}
}

@Test
public void shouldGetAUserFromXML() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
Mapper mapper = sqlSession.getMapper(Mapper.class);
Map<String, Object> params = new HashMap<String, Object>();
params.put("id", 1);
params.put("name", "User1");
User user = mapper.getUserXML(params);
Assert.assertEquals("User1", user.getName());
} finally {
sqlSession.close();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
*/
package org.apache.ibatis.submitted.maptypehandler;

import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface Mapper {

@Select("select * from users where id = #{id}")
User getUser(@Param("id") Integer id, @Param("name") String name);

@Select("select * from users where id = #{id} and name = #{name}")
User getUserFromAMap(Map<String, Object> params);

User getUserXML(Map<String, Object> params);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<mapper namespace="org.apache.ibatis.submitted.maptypehandler.Mapper">

<select id="getUser" resultType="org.apache.ibatis.submitted.maptypehandler.User">
<select id="getUserXML" resultType="org.apache.ibatis.submitted.maptypehandler.User" parameterType="map">
select * from users where id = #{id} and name = #{name}
</select>

Expand Down

0 comments on commit 4045a0a

Please sign in to comment.