2016-12-14 19 views
1

Oracleで7つのパラメータを受け取って5を返すストアドプロシージャを呼び出していますが、2つのパラメータに興味があります。 これは私が複数のIN OUTパラメータと注釈を使用してMyBatisでストアドプロシージャを呼び出す

@Select(value = "{CALL prc_ultimo_nombramiento(#{tipoIdentificacion, mode=IN},#{numeroIdentificacion, mode=IN},#{idEt, jdbcType=VARCHAR},#{fechaPosesion, mode=OUT, jdbcType=VARCHAR},#{idTipoNombramiento, mode=OUT, jdbcType=VARCHAR},#{validar, jdbcType=VARCHAR},#{mensaje, jdbcType=VARCHAR})}") 
@Options(statementType = StatementType.CALLABLE) 
@ResultType(CPDatosDocente.class) 
CPDatosDocente obtenerDatosFechaPosesionIdNombramiento(CPDatosDocente datosDocente); 

私CPDatosDocenteは、私はとても必要なすべての変数を含むPOJOで選択しMyBatisのです。

String idTipoNombramiento; 
String validar; 
String mensaje; 
String fechaPosesion; 
String tipoIdentificacion; 
String numeroIdentificacion; 
String idEt; 
//Getters and setters... 

私はMyBatisのセンテンスを呼んでいるが、私はプロシージャを呼び出すときに、私のオブジェクト(CPDatosDocente)は

public CPDatosDocente obtenerFechaPosesionIdNombramiento(Long tipoIdentificacion, 
     Long numeroIdentificacionDocente) { 
    SqlSession session = sf.openSession(); 
    try { 
     // Se abre conexión con el mapper 
     CPDatosDocenteMapper mapper = session.getMapper(CPDatosDocenteMapper.class); 
     // Se ejecuta la consulta para obtener la fecha de posesión y el 
     // tipo de nombramiento 
     CPDatosDocente datos = new CPDatosDocente(); 
     datos.setTipoIdentificacion(tipoIdentificacion); 
     datos.setNumeroIdentificacion(numeroIdentificacionDocente); 

     CPDatosDocente datosDocente =  mapper.obtenerDatosFechaPosesionIdNombramiento(datos); 
     System.out.println(datosDocente.getFechaPosesion()); 


     return datosDocente; 

    } finally { 
     session.close(); 
    } 

} 

nullで、私は多くのことを試してみましたが、私は持っているDAOを持っています必要なパラメータOUTを持つオブジェクトを取得できませんでした。

+0

エラーメッセージが表示されますか?それ以外に5つのOUTパラメータがあると言っていますが、2つしか提供していません。2つしか使用していないのに5つをすべて提供してください。 Oracleは、プロシージャのシグネチャと一致するプロシージャの呼び出しを受け取る必要があります。 – FDavidov

答えて

1

私はいくつかの変更をしたので、私は "「datosDocenteをして使用して" 削除datosをこの問題を解決することができます。

Mapper.java: 

@Select(value = "{CALL prc_ultimo_nombramiento(#{tipoIdentificacion, mode=IN},#{numeroIdentificacion, mode=IN},#{idEt, jdbcType=VARCHAR},#{fechaPosesion, mode=OUT, jdbcType=VARCHAR},#{idTipoNombramiento, mode=OUT, jdbcType=VARCHAR},#{validar, jdbcType=VARCHAR},#{mensaje, jdbcType=VARCHAR})}") 
@Options(statementType = StatementType.CALLABLE) 
@ResultType(CPDatosDocente.class) 
void obtenerDatosFechaPosesionIdNombramiento(CPDatosDocente datosDocente); 
//I put this field void because I don't need this method return nothing. 

DAO.java 

その他の変更。

public CPDatosDocente obtenerFechaPosesionIdNombramiento(String tipoIdentificacion, 
     String numeroIdentificacionDocente) { 
    SqlSession session = sf.openSession(); 
    try { 
     // Se abre conexión con el mapper 
     CPDatosDocenteMapper mapper = session.getMapper(CPDatosDocenteMapper.class); 
     // Se ejecuta la consulta para obtener la fecha de posesión y el 
     // tipo de nombramiento 
     CPDatosDocente datosDocente = new CPDatosDocente(); 
     //Se setean los parámetros necesarios para ejecutar el procedimiento 
     datosDocente.setTipoIdentificacion(tipoIdentificacion); 
     datosDocente.setNumeroIdentificacion(numeroIdentificacionDocente);   
     mapper.obtenerDatosFechaPosesionIdNombramiento(datosDocente); 
     return datosDocente; 
    } finally { 
     session.close(); 
    } 

} 

私は私のオブジェクトdatosDocenteを再利用し、Iよメソッド "obtenerFechaPosesionIdNombramiento"を呼び出すと、オブジェクトに自動的にパラメータが保存されます。 これですべてうまくいきます。私はblackwizardからのアドバイスに従い、マッパーのメソッドを無効にします。

3

Outパラメーターを選択としてプロシージャー呼び出しを考慮しないでください。

マッパーメソッドはvoidを返す必要があります。@ResultTypeは忘れてしまいます。

@Select(value = "{CALL prc_ultimo_nombramiento(#{tipoIdentificacion, mode=IN},#{numeroIdentificacion, mode=IN},#{idEt, jdbcType=VARCHAR},#{fechaPosesion, mode=OUT, jdbcType=VARCHAR},#{idTipoNombramiento, mode=OUT, jdbcType=VARCHAR},#{validar, jdbcType=VARCHAR},#{mensaje, jdbcType=VARCHAR})}") 
@Options(statementType = StatementType.CALLABLE) 
void obtenerDatosFechaPosesionIdNombramiento(CPDatosDocente datosDocente); 

OUTパラメータは、マッパーメソッドに渡されるパラメータdatosDocenteに書き込まれます。 INパラメータを持ち、OUTパラメータのターゲットです。

+0

ありがとうございますblackwizard、あなたは正しい、私は多くを試して、私は私のプロシージャを実行するとき、私は必要がないオブジェクトCPDatosDocenteを使用している私のエラーを見つけた、すべてのパラメータは "datos"と"datosDocente"ではなく、その理由は私が検索したすべてがnullだったからです。再度、感謝します。 – Allanh

+0

@Allanh:あなたのために、あなたはその質問に回答としてマークすることができます。 – blackwizard

+0

OK。私は答えとしてマークするつもりですが、私はこのために行った変更が必要です。 – Allanh

関連する問題