Thanks François!
Creating a real table, like you said, might be a solution... here is
the code and config files that i've been using:
// ----------------------------- Begin Test class
public class Teste {
private Logger log = Logger.getLogger(Teste.class);
private SqlSessionFactory sqlMapper = null;
private void inicializeMyBatis() {
Reader reader = null;
try {
log.info("Configuring MyBatis");
String path = "br/com/mercur/dao/mybatis/
Configuration.xml";
reader = Resources.getResourceAsReader(path);
log.info(new StringBuilder().append("Config File:
").append(path));
sqlMapper = new SqlSessionFactoryBuilder().build(reader);
log.info("MyBatis configured!");
} catch (IOException ex) {
log.fatal("Error while reading MyBatis config file!", ex);
} finally {
try {
reader.close();
} catch (IOException ex) {
log.fatal("Error while closing MyBatis config file!",
ex);
}
}
}
public void testar() {
inicializeMyBatis();
SqlSession session = sqlMapper.openSession();
// Mapper interface for my querys
DAO_CargaDadosRepresentante daoCargaDadosRep =
session.getMapper(DAO_CargaDadosRepresentante.class);
HashMap<String,Object> params = new HashMap<String, Object>();
params.put("cod_rep", 275);
params.put("un_negocio", 3);
params.put("cod_grupo", 2);
try {
daoCargaDadosRep.criaTempTables(params);
daoCargaDadosRep.getClientes(275, 1, "3");
} catch (Exception e) {
log.error("", e);
}
session.close();
}
public static void main(String[] args) {
Teste t = new Teste();
t.testar();
}
}
// ----------------------------- End Test class
// ----------------------------- Begin Configuration.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>
<environments default="server">
<environment id="server">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver"
value="net.sourceforge.jtds.jdbc.Driver"/>
<property name="url" value="jdbc:jtds:SqlServer://
server:1433/Prim_EMS"/>
<property name="username" value=""/>
<property name="password" value=""/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="br/com/mercur/dao/mybatis/mapper/
CargaDadosGerais.xml"/>
<mapper resource="br/com/mercur/dao/mybatis/mapper/
CargaDadosCliente.xml"/>
<mapper resource="br/com/mercur/dao/mybatis/mapper/
CargaDadosPoliticaComercial.xml"/>
<mapper resource="br/com/mercur/dao/mybatis/mapper/
CargaDadosRepresentante.xml"/>
<mapper resource="br/com/mercur/dao/mybatis/mapper/
Estatistica.xml"/>
</mappers>
</configuration>
// ----------------------------- End Configuration.xml
// ----------------------------- Begin CargaDadosRepresentante.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="br.com.mercur.dao.DAO_CargaDadosRepresentante">
<update id="criaTempTables" parameterType="hashmap">
<![CDATA[
CREATE TABLE ##tmpCliRep ( cod_emitente int )
INSERT INTO ##tmpCliRep
SELECT cod_emitente FROM
fun_getClientesUsuarioRep(#{cod_rep},#{cod_grupo})
]]>
</update>
<select id="getClientes" resultType="hashmap">
<![CDATA[
select cod_emitente from ##tmpCliRep
]]>
</select>
</mapper>
// ----------------------------- End Configuration.xml
On the last config file i've omitted the other mapped querys, just
left the two that are used on the test. I have tested the creation of
the temp table on a <insert>, <select> and <update> elements. Tried to
put a session.commit() after the
daoCargaDadosRep.criaTempTables(params); and I still cannot access the
temp table.
On 22 fev, 11:55, François Schiettecatte <
fschietteca...@gmail.com>
wrote: