lundi 6 avril 2015

Parameters not parsing to my batis mapper via a java.util.Map


Vote count:

0




I have following method,



public Project getProjectByUser(long userId, String projectName)
throws IOException {

SqlSession sqlSession = null;
Project response = null;

Map<String, Long> projectParam = new HashMap<String, Long>();
projectParam.put("userId", userId);

try {

sqlSession = DBSessionManager.getInstance().getSessionFactory()
.openSession();

LOG.debug("SqlSession opened for Project mapper");

ProjectMapper projectMapper = sqlSession
.getMapper(ProjectMapper.class);

sqlSession.insert("getProjectByUserId", projectParam);
sqlSession.commit();

response = projectMapper.getProjectByUserId(userId);

} finally {
if (sqlSession != null) {
sqlSession.close();
LOG.debug("SqlSession closed");
} else {
System.out.println("_sql session null");
}

}

return response;
}


And in xml file i have the following code.



<select id="getProjectByUserId" resultMap="projectResultMap"
parameterType="map" flushCache="false" useCache="false">
SELECT
project_id,
user_id, project_name,
created_date,
last_updated_date FROM
project
WHERE
user_id=#{userId}
</select>


When I replaced (hard coded the value) the user_id=#{userId} part as user_id=1 expected result is returned. But when I pass it from client application though the value is set to the map correctly the query doesn't get it correct and results in a null return. What am I doing wrong here.


My ProjectMapper class's method definition is,



public Project getProjectByUserId(long userIdParam);


asked 41 secs ago







Parameters not parsing to my batis mapper via a java.util.Map

Aucun commentaire:

Enregistrer un commentaire