Tag Archives: mybatis

[spring/mybatis] 오라클(oracle) 프로시저(procedure) 파라미터가 배열(array)일 경우 mybatis typehandler 예제

By | 12월 28, 2023

oracle type object CREATE OR REPLACE TYPE 스키마."VARR" IS TABLE OF VARCHAR2(2048); TypeHandler import oracle.jdbc.Oracleconnection; import org.apache.ibatis.type.BaseTypeHandler; import org.apache.ibatis.type.JdbcType public class VarrTypeHandler extends BaseTypeHandler<Object> { /** * DB에서 관리중인 Type의 이름 * – DB에 이 이름으로 Type Object가 미리 준비되어 있어야 함. */ private static final String TYPE_NAME = "VARR"; /** * 최초 구현하지 않았던… Read More »

MyBatis insert 문 사용시 PK 획득하기 (useGeneratedKeys)

By | 9월 25, 2021

mybatis query xml <insert id="insertBook" useGeneratedKeys="true" keyProperty="bookId"> INSERT /* insertBook */ INTO book ( book_title ) VALUES ( #{bookTitle} ) </insert> 쿼리 이후 result 객체가 아닌 parameter 객체에서 bookId 를 참조하면 PK 획득. 이 테이블의 PK는 book_id 이지만 auto increment 이기 때문에 쿼리에는 기재되지 않았음. 대신 keyProperty 에 프로퍼티명이 명시되어 있음 mybatis config에 mapUnderscoreToCamelCase 가… Read More »

Mybatis 오류 어리둥절 케이스 (Error setting non null for parameter #12 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Could not set parameter at position 12 (values was ‘1’))

By | 6월 23, 2021

이 오류의 해결을 위해서 한참을 헤멨는데, mybatis mapper config 의 jdbcTypeForNull 을 NULL로 해 주라느니 등등 이것저것 해 봤지만 아무리 해도 듣지 않았다. 변수 바인딩 표현식 #{}도 오타/누락 등의 문제 없었고, 파라미터 갯수도 문제 없고. 그러다가 그냥 기존 xml 쿼리를 밀고 다시 짰더니 됐다. -_-… 뭐지..뭐였지…

[링크] MyBatis 1:N select 결과 매핑하는 예제 (e.g. 게시물 목록조회시 게시물당 첨부파일목록을 함께 조회하여 그룹핑, group, collection, one to many)

By | 7월 8, 2021

[Mybatis] 1:N 관계 데이터 처리 data concatenation 주의사항 resultMap > collection 을 사용할 경우 collection 의 요소가 두 개 이상일 경우(거의 그렇겠지만) 평범한 페이징으로는 오류가 날 수 밖에 없다. offset, limit 등은 그룹핑 후에 걸어야 하는데, collection의 경우 쿼리가 다 끝나고 그룹핑 되므로 그래서 나는 그냥 resultMap-collection 패턴을 포기하고 주 레코드만 select 후, select된 목록의… Read More »

[자작] MyBatis EHCache 를 필요에 따라 statement 별로 제거하기

By | 4월 29, 2020

import java.util.List; import org.apache.ibatis.cache.CacheKey; import lombok.extern.slf4j.Slf4j; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; /** * MyBatis EHCache 관련 유틸 클래스 * * – mapperId + statementId 에 대하여 exactly equals 가 아니라 contains 임에 주의 * * @author STEVE */ @Slf4j public class MyBatisCacheUtil { /** * MyBatis 쿼리 캐시 제거 * * @param mapperId (e.g. “com.example.repository.UserRepository”) *… Read More »

MyBatis에 EHCache 적용하기

By | 4월 28, 2020

1. pom.xml <dependency> <groupId>org.mybatis.caches</groupId> <artifactId>mybatis-ehcache</artifactId> <version>1.2.1</version> </dependency>   2. MyBatis 각 mapper 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=”com.tachyon.api.repository.NewsRepository”> <!– MyBatis ehcache 설정 – http://mybatis.org/ehcache-cache/ –> <cache type=”org.mybatis.caches.ehcache.EhcacheCache”> <!– <cache type=”org.mybatis.caches.ehcache.EhBlockingCache”> –><!– blocking cache를 사용할 경우 –> <property name=”timeToIdleSeconds” value=”3600″/><!–1 hour–> <property name=”timeToLiveSeconds” value=”3600″/><!–1 hour–> <property name=”maxEntriesLocalHeap” value=”1000″/> <property… Read More »