ibatis

How to handle an Empty IN clause inside a SQL Select Statement (IBatis 2)?

一世执手 提交于 2019-12-13 04:48:56
问题 I have written the following SQL Statment in IBatis version 2: <select id="mySelect" resultClass="long" > SELECT COUNT(*) FROM myTable WHERE myTable.columnA IN <iterate property="myInClauseValues" open="(" close=")" conjunction=","> #myInClauseValues[]# </iterate> </select> That statement works fine, if myInClauseValues (this is a ArrayList with Long) include at least one value. But if myInClauseValues is empty, I get an error message like this (I´m using an oracle database): Check the

MyBatis CDI + Container-Managed Transaction

假装没事ソ 提交于 2019-12-13 03:45:43
问题 I would like to use mybatis with container-managed transaction in my aplication. I use mybatis 3.4.2 and mybatis-cdi 1.0.0. My code works but at the moment I open and close sessions manually and I do not know how to inject either SqlSession or Mapper to my EJB. It seems that mybatis-cdi does not do its job properly in my case. That is my deployment structure: EAR +--- commons.jar (interfaces, POJOs) +--- ejb.jar (stateless EJBs + MyBatis mapper + session factory) +--- web.war (demo servlet

How do configure the dao files to handle inserting a List<String> in MyBatis

可紊 提交于 2019-12-13 03:37:39
问题 I have an object that has a variable that's a List like so: ExportQueue.java public class ExportQueue implements Serializable { private List<String> errors; public List<String> getErrors() { return errors; } public void setErrors(List<String> errors) { this.errors = errors; } public void addError(String error) { if(this.errors == null) this.errors = new ArrayList<String>(); this.errors.add(error); } } I've defined the ResultMap for this... ExportQueueDao.xml <mapper namespace="...">

Ibatis queryWithRowHandler() still seems to fetch all rows

寵の児 提交于 2019-12-13 03:30:46
问题 I'm using Ibatis 2.3.4 and Mysql 5.1.37, with mysql-java-connector 5.1.6 with java 1.6 I have query that returns very many rows from a single table. In order to do this the manual suggests to use queryWithRowHandler() . However when I call this query it internally still seems to fetch all rows (memory goes up very fast before the first handleRow() call is done. How can I tell Ibatis to fetch small at the time portions (I can of course use several queries returning lists of smaller results,

MyBatis: java.sql.SQLException: Invalid java.sql.Types constant value -9 passed to set or update method

℡╲_俬逩灬. 提交于 2019-12-13 03:02:58
问题 Im getting this error when calling a Stored_Procedure in SqlServer from MyBatis: > ### Error querying database. Cause: java.sql.SQLException: Invalid java.sql.Types constant value -9 passed to set or update method. > ### The error may exist in mybatis-mapper/UpstreamMapper.xml > ### The error may involve callStoredProcedure > ### The error occurred while executing a query > ### SQL: {call dbo.get_discount_value(?,?, ?,?,?,?)} > ### Cause: java.sql.SQLException: Invalid java.sql.Types constant

Dynamic Select SQL statements with MyBatis

旧巷老猫 提交于 2019-12-13 00:46:15
问题 I would like to have dynamic sql statements using mybatis in an Oracle 12g database where I can utilize a hash map to add conditionals something like the following: <select id="getUsers" resultType="hashmap" parameterType="hashmap"> select * from users <where> <iterate var="i=0" increment> ${columni} like #{valuei} </iterate> </where> </select> Is there a way for me to accomplish something like that? 回答1: From documentation: String Substitution By default, using the #{} syntax will cause

22mybaits注解开发

孤街醉人 提交于 2019-12-12 22:32:14
这几年来注解开发越来越流行,Mybatis 也可以使用注解开发方式,这样我们就可以减少编写 Mapper 映射文件了。 1.常用注解说明 @Insert:实现新增 @Update:实现更新 @Delete:实现删除 @Select:实现查询 @Result:实现结果集封装 @Results:可以与@Result 一起使用,封装多个结果集 @ResultMap:实现引用@Results 定义的封装 @One:实现一对一结果集封装 @Many:实现一对多结果集封装 @SelectProvider: 实现动态 SQL 映射 @CacheNamespace:实现注解二级缓存的使用 2.使用Mybatis注解实现基本CRUD 2.1查询数据库 2.2创建maven工程导入jar包的坐标 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion

MyBatis full annotation config to retrieve stored procedure result in OUT parameter?

喜你入骨 提交于 2019-12-12 19:25:11
问题 We have an Oracle stored procedure that returns its results in a SYS_REFCURSOR type OUT parameter. We would like to call this through a MyBatis mapper, the relevant part of the query string in the @Select annotation looks as follows @Select(value="call " + SCHEMA_NAME + "." + STORED_PROCEDURE_NAME + "(" + ... "#{" + P_RECORDSET_FIELD + ",javaType=java.sql.ResultSet,jdbcType=CURSOR,mode=OUT,resultMap=ownNameSpace.ownResultMap}," + ... where the resultMap property refers to the following XML

java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()

旧城冷巷雨未停 提交于 2019-12-12 17:16:18
java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; 报错解决 在mybatis+spring整合中,由于版本的问题会报错: java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org

介绍MyBatis代码生成网站(四) --- 继承基类

为君一笑 提交于 2019-12-12 12:24:31
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一.简介 网址: http://www.fwjava.com 操作流程: 详见 “ 介绍MyBatis代码生成网站(一) --- 基本操作 ” 需求描述: 1. 需要在生成的所有 Java实体中 , 继承 公司提供的com.icsm.common.BaseEntity类 2. 需要在生成的所有 Java实体中 , 实现 公司提供的com.icsm.common.IEntity接口类 3. 需要在生成的所有 Mapper接口类中 , 继承 公司提供的com.icsm.common.BaseMapper接口类 二.操作 在网站的[2.属性设置] 页面中 , 填写路径即可. 2-1 Java实体 如下图: 图标1) 在生成的所有 Java实体中 , 继承 公司提供的com.icsm.common.BaseEntity类 图标2) 在生成的所有 Java实体中 , 实现 公司提供的com.icsm.common.IEntity接口类 2-2 Mapper接口类 图标3) 在生成的所有 Mapper接口类中 , 继承 公司提供的com.icsm.common.BaseMapper接口类 三.实际效果 3-1 Java实体 package com.icsm.paybank.entity; import com.icsm