Reputation: 1648
I have a question similar to this question: Passing list parameter in iBatis 2.3.0, because I'm adding another Mapper (I have another mapper working without problems) Unfortunately with my new one I got this Exception:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.io.IOException: Failed to parse mapping resource: 'class path resource [mappers/EstadoCertificadoMapper.xml]'
.
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory
method 'sqlSessionFactory' threw exception; nested exception is
java.io.IOException: Failed to parse mapping resource:
'class path resource [mappers/EstadoCertificadoMapper.xml]'
I'm using:
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.3.2'
implementation "org.springframework:spring-jdbc:5.3.39"
I created my XML based on https://stackoverflow.com/a/33435436.
This is the content of EstadoCertificadoMapper.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="organization.repository.mapper.EstadoCertificadoMapper">
<resultMap id="estadoCertificadoResultMap"
type="organization.model.EstadoCertificadoModel">
<result column="id_solicitud" property="idSolicitud"/>
<result column="is_valid_json_v16" property="isValidJsonV16"/>
<result column="is_blank_json_v16" property="isBlankJsonV16"/>
</resultMap>
<select id="buscarEstadosCertificados" parameterType="listaIds" resultType="EstadoCertificadoModel">
SELECT
id_solicitud,
CASE
WHEN ISJSON(json_v16) = 1 THEN 'true' ELSE 'false'
END AS is_valid_json_v16,
CASE
WHEN LTRIM(RTRIM(json_v16)) IS NULL OR LTRIM(RTRIM(json_v16)) = '' THEN 'true' ELSE 'false'
END AS is_blank_json_v16
FROM tabla_certificado
WHERE id_solicitud IN
<foreach item='item' index='index' collection='listaIds' open='(' separator=',' close=')'>"
#{item}
</foreach>
</select>
</mapper>
The model class: EstadoCertificadoModel
package organization.model;
import lombok.*;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EstadoCertificadoModel {
private String idSolicitud;
private boolean isValidJsonV16;
private boolean isBlankJsonV16;
}
The mapper class: EstadoCertificadoMapper
package organization.mapper;
import organization.model.EstadoCertificadoModel;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface EstadoCertificadoMapper {
@ResultMap("estadoCertificadoResultMap")
List<EstadoCertificadoModel> buscarEstadosCertificados(@Param("listaIds") List<String> listaIdSolicitudes);
}
I suspect the problem is only in my XML file. But I was reading the MyBatis documentation (dynamic-sql, sqlmap-xml) and for me is not enough clear.
I would like to get a List of custom Object using a List of codes. I was testing with annotation and these answer but comment says that it only works for myBatis 3.
Could you tell me how to fix my XML
file or/and EstadoCertificadoMapper
class?
I have doubts about resultType
value on select
section of the XML
file.
Upvotes: 0
Views: 13