Fetching records from cursor using Mybatis

174 views
Skip to first unread message

ANKIT SIRMORYA

unread,
Jul 12, 2013, 10:06:46 AM7/12/13
to mybati...@googlegroups.com

Hi,

I am quite new to mybatis and i have been trying to fetch records from cursor using Mybatis.

XML File :

 <resultMap id="accountDetailResult" type="student">
     <result property="firstName" column="First_Name" />
    <result property="lastName" column="Last_Name" />
   
    </resultMap>

    <select id="getAccountDetail" parameterType="map" statementType="CALLABLE">
   { #{t_students_cursor,jdbcType=CURSOR,mode=OUT,resultMap=accountDetailResult,javaType=java.sql.ResultSet} =
    call students.student_fetch(#{osisId,jdbcType=VARCHAR,mode=IN}, #{userId,jdbcType=VARCHAR,mode=IN},#{programCode,jdbcType=VARCHAR,mode=IN})}
    </select>



POJO Class :

public class Student {
   

    private String firstName;

    private String lastName;

    // private String relationshipToStudent;
    private String emailAddress;

    private String daytimeTelephoneNumber;

    private String eveningTelephoneNumber;

    private String osisId;
     
    private String userId;
   
    private String programCode;

Mapper Interface :

public interface ProductServices {

void getAccountDetail(@Param("map") Map<String, Object> parameter);



Tester Class  :

Map<String, Object> param = new HashMap<String, Object>();
            param.put("p_osis_id", "214726788");
            param.put("p_usr_id", "admin");
            param.put("p_program_code", null);

 productServiceObj.getAccountDetail(param);
 Student st = (Student)param.get("t_students_cursor");


PL/SQL Function


FUNCTION student_fetch(
  p_osis_id      VARCHAR2,
  p_usr_id       VARCHAR2,
  p_program_code VARCHAR2)
 RETURN t_students_cursor
IS
 cur t_students_cursor;
 --v_cnt INT;
BEGIN
 --check_student_info_permission(p_osis_id, p_usr_id, p_program_code, v_cnt);
 --IF v_cnt  > 0 THEN
 OPEN cur FOR SELECT srec.First_Name, srec.Last_Name, srec.Middle_Initial,
 . . .


Exception :

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.NullPointerException
### The error may involve com.example.services.ProductServices.getAccountDetail-Inline
### The error occurred while setting parameters
### Cause: java.lang.NullPointerException
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:61)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:53)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:38)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:66)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:35)
    at $Proxy1.getAccountDetail(Unknown Source)
    at com.example.runner.AppTester.main(AppTester.java:79)
Caused by: java.lang.NullPointerException






Raúl

unread,
Jul 12, 2013, 6:38:13 PM7/12/13
to mybati...@googlegroups.com
when I call a function I usually use the <update tag instead of <select

Ankit

unread,
Jul 15, 2013, 3:38:35 AM7/15/13
to mybati...@googlegroups.com
Have changed <select to &lt;update still not working.
:(


&lt;update id=&quot;getAccountDetail&quot; parameterType=&quot;map&quot;
statementType=&quot;CALLABLE&quot; >
{
#{t_students_cursor,jdbcType=CURSOR,mode=OUT,resultMap=accountDetailResult,javaType=java.sql.ResultSet}
=
call students.student_fetch(#{osisId,jdbcType=VARCHAR,mode=IN},
#{userId,jdbcType=VARCHAR,mode=IN},#{programCode,jdbcType=VARCHAR,mode=IN})}
</update>



--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Fetching-records-from-cursor-using-Mybatis-tp4027190p4027195.html
Sent from the mybatis-user mailing list archive at Nabble.com.

Dario Arizabalo

unread,
Aug 30, 2013, 8:28:12 AM8/30/13
to mybati...@googlegroups.com
Hi, you can map the resultMap directly, and then get the mapped  result by the method selectList() in your test class.

         <select 
id="getAccountDetail" 
parameterType="map" 
statementType="CALLABLE" 
resultMap="accountDetailResult">
call students.student_fetch(
#{osisId,jdbcType=VARCHAR,mode=IN},
#{userId,jdbcType=VARCHAR,mode=IN},
#{programCode,jdbcType=VARCHAR,mode=IN}
)
Reply all
Reply to author
Forward
0 new messages