프로퍼티 값이 분명이있는데 찾지 못한다고할때 .
 remapResults="true"
써준다.

그런데, 여기서 테이블명이 바뀌면 읽어오는 필드명도 보통은 달라지게마련..

iBatis는 내부적으로 읽어온 결과의 metadata를 저장해두는데

읽어온 필드명이 달라지면 이전의 metadata와 mapping이 되지않아 에러를 발생시킨다. 

이럴때 statement의 attribute로 "remapResults=true"를 추가해줘야 한다.

이렇게 되면 매번 metadata를 세팅하므로 사실은 오버헤드가 있지만 에러는 발생하지 않는다

<select id="getPerson" parameterClass=”int” resultClass="xml" xmlResultName=”person”>
SELECT
PER_ID as id,
PER_FIRST_NAME as firstName,
PER_LAST_NAME as lastName,
PER_BIRTH_DATE as birthDate,
PER_WEIGHT_KG as weightInKilograms,
PER_HEIGHT_M as heightInMeters
FROM PERSON
WHERE PER_ID = #value#
</select>
위 select 구문은 다음 구조의 XML객체를 생성할 것이다.
<person>
<id>1</id>
<firstName>Clinton</firstName>
<lastName>Begin</lastName>
<birthDate>1900-01-01</birthDate>
<weightInKilograms>89</weightInKilograms>
<heightInMeters>1.77</heightInMeters>
</person>
<parameterMap id=”insert-product-param” class=”com.domain.Product”>
<parameter property=”id”/>
<parameter property=”description”/>
</parameterMap>
<insert id=”insertProduct” parameterMap=”insert-product-param”>
insert into PRODUCT (PRD_ID, PRD_DESCRIPTION) values (?,?)
</insert>

com.domain.Product 클레스로 넘어온값을
파라메타를 다시 제정의한다 순서를 정한다.
그후
인서트 부분에
? ?
 순서대로 들어간다

insert into PRODUCT (PRD_ID, PRD_DESCRIPTION) values (id값이들어오고,description값이온다)



<!--  테이블 구조와 where 구조를 블럭화 한다 -->
<sql id="selectItem_fragment">
FROM items
WHERE parentid = 6
</sql>
<!-- 셀렉트 문 밑에 iclude 를 이용하여 붙여 넣기했다 -->
<select id="selectItemCount" resultClass="int">
SELECT COUNT(*) AS total
<include refid="selectItem_fragment"/>
</select>

<select id="selectItems" resultClass="Item">
SELECT id, name
<include refid="selectItem_fragment"/>
</select>


<!-- 파라메타 있는 구분도 가능 하다 -->

<sql id="selectItem_fragment">
FROM items
WHERE parentid = #value#
</sql>
<select id="selectItemCount" parameterClass="int" resultClass="int">
SELECT COUNT(*) AS total
<include refid="selectItem_fragment"/>
</select>
<select id="selectItems" parameterClass="int" resultClass="Item">
SELECT id, name
<include refid="selectItem_fragment"/>
</select>


maxRequests - 실행되는 쓰레드 갯수
maxSessions -
maxRequests   작게 maxTransactions 크게 설정한다. 최대치줄이면 메모리 사용량을 줄일수있다.
이유 - DB에 맺는 세션인데 생성자를 생성하는거다 컴퓨터에 가장 많은 부하를 일으키는것이
1. 파일 읽고 쓰기
2. 네트워크 요청 커넥션
3. 기타 IO
일명 IO라고 하겠다.
IO를 미리 맺어놓는 역활을 하는것이 Session 인데.. 이분분에는 생성자가 생기고 매모리가 추가된다 이때문에 매모리 가 늘어날수박에없다.
DB의 세션 한계도 한번 체크해보자 .!!
maxTransactions -
이것은 한꺼번에 SqlMapClient.startTransaction()에 들어갈수 있는 쓰레드
의 최대갯수이다.  maxSessions보다 작거나 같고 maxRequests보다 작아야함
이것은 DB의에 명령을 한번에할수있는부분이다.. 셀렉트는 시간이 오래걸리고 인서트는 금방한다. 모 차이는 종종있겠지만 .이런 부분을 한거번에 처리하는 갯수

cacheModelsEnabled -
이 셋팅은 SqlMapClient 를 위한 모든 캐쉬모델을 가능하게 하거나 가능하지 않게 한다. 이것은 디버깅시 도움이 된다.
enhancementEnabled -
 
이 셋팅은 향상된 늦은(lazy)로딩처럼 최적화된 자바빈즈 속성 접근을 위해 런
타임시 바이트코드 향상을 가능하게 한다.

useStatementNamespaces -
이 셋팅을 가능하게 하면 당신은 sqlmap이름과 statement이름으로 구성된 전
체적인 이름(fully qualified name)으로 매핑 구문를 참조해야 한다.


 
 
다량의 인서트와 업데이트 할때 유용하다.


SqlMapClient client = getSqlMapClient();
try{
client.startTransaction(); //선언해죠야하낟.
client.startBatch();
for (int i = 0; i < listDeptIDs.size(); i++) {
Object res = getSqlMapClientTemplate().queryForObject("select-role-dept", params); // 객체있는지 판단
   //System.out.println("res : " + res + ", " + deptid + " : " + rid);
   if (res == null || Integer.parseInt("" + res) <= 0) {
    client.insert("insert-role-dept", params); // 인서트할 쿼리를 넣는다.
   }
}
client.executeBatch();
} catch (Exception e) {
   e.printStackTrace();
   return false;
  } finally {
   try {
    client.endTransaction(); // 종료 확실히
   } catch (Exception e) {
    e.printStackTrace();
    return false;
   }
  }

잘사용하자.

펌 - http://naucika.tistory.com/63
오라클  Sequence
 <insert id="extractionDao.insertNumber" parameterClass="ExtractionInfoBean">   
     <selectKey resultClass="log" keyProperty="id" >
      <![CDATA[           
    select event_seq.nextval from dual     
   ]]>
     </selectKey>
   <![CDATA[ 
    insert into event ( type, id, extension ) values ( #type#, #id#, #extension# )   
   ]]>          
 </insert> 


<!— Microsoft SQL Server IDENTITY Column Example -->
<insert id="insertProduct-MS-SQL" parameterClass="com.domain.Product">
insert into PRODUCT (PRD_DESCRIPTION)
values (#description#)
<selectKey resultClass="int" >
SELECT @@IDENTITY AS ID
</selectKey>
</insert>

1. 주의할점
-->keyProperty 는 parameterClass넘어오는 객체에 Set 과 Get으로 이름이존재해야한다.
--> parameterClass 클래스 객체의 타입과 resultClass="log" 의 값은 같아야한다.
--> DB 형식에 따라 selectKey  의 위치가 틀려질수있다.
      오라클은 먼저 MYSQL 및 MS_SQL은 뒤에 입력해야한다. 그이유는 DB 마다 스킨스 생성하는 방식이 틀리기 떄문이다.