How to send multiple parameters to in many=@Many(select) nested select call?

37 views
Skip to first unread message

Micky

unread,
May 16, 2013, 12:46:54 AM5/16/13
to mybati...@googlegroups.com
I have a scenario wherein I need to send parameter to many=@Many(select) call. I am not sure how to do so.



@Select(GET_EMPLOYEE)
@Results(value = {
@Result(property="id", column="ID"),
                        @Result(property="dept", column="ID", javaType=List.class, many=@Many(select="getDepts"))
})
public Employee getEmployee(Object param);


Now in the getDepts() method I need to be able to pass param object. How can this be achieved?


@Select(GET_DEPTS)
@Results(value = {
@Result(property="id", column="ID"),
                        @Result(property="deptName", column="NAME")
})
public Employee getDepts(@Param("id")Long id, @Param("param")Object param);







Iwao AVE!

unread,
May 22, 2013, 8:37:23 PM5/22/13
to mybatis-user
Hi,

There is no way to pass the original parameter object to the nested
select, but you can pass multiple parameters.
Assuming that GET_DEPTS needs two parameters 'employeeId' and
'country' and GET_EMPLOYEE returns ID and COUNTRY as its results:

@Select(GET_EMPLOYEE)
@Results(value = {
@Result(property="id", column="ID"),
@Result(property="dept", column="{employeeId=ID,country=COUNTRY}",
javaType=List.class, many=@Many(select="getDepts"))
})
public Employee getEmployee(Object param);

@Select("select * from dept where employee_id = #{employeeId} and
country = #{country}")
@Results(value = {
@Result(property="id", column="ID"),
@Result(property="deptName", column="NAME")
})
public Employee getDepts(Map params);

Note that the parameter type of the nested select is now java.util.Map.

Hope this helps,
Iwao

2013/5/16 Micky <viren....@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mybatis-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Viren Chande

unread,
May 23, 2013, 11:46:13 AM5/23/13
to mybati...@googlegroups.com
Many thanks Iwao for your reply. It does help to know that multiple parameters can be passed in a manner you explained. But I was looking to pass the original parameter from 'getEmployee' method to the nested select.

Also, I appreciate that you confirmed the fact that original parameter object cant be passed to the nested select.

Thanks once again lwao.
Reply all
Reply to author
Forward
0 new messages