2011-09-07 8 views
1

現在、iBatisからmyBatisへのアップグレードに取り組んでいます。 iBATISは、我々のようなSQLマップを持つことになりそうMyBatis&RefCursorパラメータ

<resultMap id="PCRV_HIERARCHY_LVL_LIST_MAP" class="com.fmrco.sai.aadpm.domain.ConstraintHierarchyLevel"> 
    <result property="levelId" column="LEVEL_ID"/> 
    <result property="levelDescription" column="LEVEL_DESCRIPTION"/> 
    <result property="levelRank" column="LEVEL_RANK"/> 
    <result property="levelCode" column="LEVEL_CODE"/> 
</resultMap> 

<parameterMap id="GET_HIERARCHY_LVL_LIST_MAP" class="java.util.Map"> 
    <parameter property="PCRV_HIERARCHY_LVL_LIST" jdbcType="ORACLECURSOR" javaType="java.sql.ResultSet" mode="OUT" resultMap="PCRV_HIERARCHY_LVL_LIST_MAP"/> 
</parameterMap> 


<procedure id="GET_HIERARCHY_LVL_LIST" parameterMap="GET_HIERARCHY_LVL_LIST_MAP"> 
    { call GET_HIERARCHY_LVL_LIST (?) } 
</procedure> 
私は完全に(例えばマッパーの実装を実装するために必要とななparameterMapとして廃止予定の機能を使用して避けないと)MyBatisの提供する機能を利用したいと思います

私はいくつかの問題があります。私は

Mapper.java 
public void getHierarchyLevels(ListConstraintHierarchyLevel constraintHierarchyLevels); 

ConstraintHierarchyLevelクラス

public class ListConstraintHierarchyLevel { 
    private List<ConstraintHierarchyLevel> constraintHierarchyLevels ; 


    public List<ConstraintHierarchyLevel> getConstraintHierarchyLevels() { 
     return constraintHierarchyLevels; 
    } 


    public void setConstraintHierarchyLevels(List<ConstraintHierarchyLevel> constraintHierarchyLevels) { 
     this.constraintHierarchyLevels = constraintHierarchyLevels; 
    } 
} 

マッパーを避けたいのですが何かあるラッパーオブジェクトに私のResultSetオブジェクトをラップする必要がありましたので、リターンのプロパティを設定しようと、エラーに走り続けました。 xml

<resultMap id="HierarchyLvlMap" type="com.fmrco.sai.aadpm.domain.ConstraintHierarchyLevel"> 
    <result property="levelId" column="LEVEL_ID"/> 
    <result property="levelDescription" column="LEVEL_DESCRIPTION"/> 
    <result property="levelRank" column="LEVEL_RANK"/> 
    <result property="levelCode" column="LEVEL_CODE"/> 
</resultMap> 

<select statementType="CALLABLE" 
    id="getHierarchyLevels" 
    parameterType="com.fmrco.sai.aadpm.domain.ListConstraintHierarchyLevel" 
    resultMap="HierarchyLvlMap"> 
    { call GET_HIERARCHY_LVL_LIST ( 
     #{constraintHierarchyLevels, 
     jdbcType=CURSOR, 
     mode=OUT, 
     javaType=java.sql.ResultSet, 
     resultMap=HierarchyLvlMap} 
    ) } 
</select> 

私は別の解決策を試みましたが失敗しました。この溶液に、私はPARAM注釈を利用する

mapper.java Iは、上記のように、異なる選択ブロック

mapper.xml

 <select statementType="CALLABLE" 
    id="getHierarchyLevelsWithParam" 
    parameterType="list" 
    resultMap="HierarchyLvlMap"> 
    { call GET_HIERARCHY_LVL_LIST ( 
     #{constraintHierarchyLevels, 
     jdbcType=CURSOR, 
     mode=OUT, 
     javaType=java.sql.ResultSet, 
     resultMap=HierarchyLvlMap} 
    ) } 
と同じこのresultMapを使用

public void getHierarchyLevelsWithParam(@Param("constraintHierarchyLevels") List<ConstraintHierarchyLevel> constraintHierarchyLevels); 

これを実行すると、私はMapperMethodクラスを実行メソッドにデバッグし、Object paramは結果セットから正しいデータを取得しますが、これは配置されません(List)を引数として渡すと、これらの値は返されません。オブジェクトラッパーを使用して最初のメソッドを実行するとき、オブジェクトは送信された引数に配置され、したがって取り出すことができます。

ありがとうございました

答えて

1

私は結果オブジェクトをラッピングする以外の方法は分かりません。 実際、OUT変数は何かにバインドされている必要があります。これは可変スコープの問題です。間接指定は必須です。しかし、それは一般的なことができます:

class Wrapper<T> { 
private List<T> member; 
} 

@Paramアノテーションは、実際にSQL(マッパーメソッドに複数のパラメータがある場合は特に)

の基準と用途にパラメータに名前を付けるために使用されます
関連する問題