Merging result-map in iBatis.

136 views
Skip to first unread message

Rhishi Nema

unread,
Apr 18, 2012, 11:09:13 AM4/18/12
to mybatis-user
Hi,

Could anyone suggest how we can integrate two result-map into one
using iBatis.

I have two List<Object> coming from two different result-map, both
list have a common id based on which merging has to be done i.e object
from one list has to be set into another object.

Please provide suggestion on this.

Thanks,
Rhishi

Dridi Boukelmoune

unread,
Apr 19, 2012, 2:20:52 AM4/19/12
to mybati...@googlegroups.com
Hi,

Have a look at discriminators, it might do the job.

Dridi

http://www.zenika.com

Rhishi Nema

unread,
Apr 20, 2012, 1:13:42 AM4/20/12
to mybati...@googlegroups.com, mybati...@googlegroups.com


Sent from my iPhone

Rhishi Nema

unread,
Apr 20, 2012, 1:19:31 AM4/20/12
to mybati...@googlegroups.com, mybati...@googlegroups.com
I want to execute a select statement from within the mapper and than use the corresponding result map to merge with other. 

I was using association to achieve this and calling select from there but this causes N+1 select problems. In order to avoid this I am using resulmap parameter directly but this is not calling the select statement.

Please suggest.

Sent from my iPhone

On 19-Apr-2012, at 11:50, Dridi Boukelmoune <dridi.bo...@zenika.com> wrote:

Dridi Boukelmoune

unread,
Apr 21, 2012, 7:28:40 AM4/21/12
to mybati...@googlegroups.com
Hi,

I'm sorry I misread your fist post.
I don't know if it's actually possible to do what you want, but here is one thing you can do :

class Main {
private long id;
private String field;
private String otherFieldToBeMerged;

// getters/setters

setMyAssociation(MyAssotiation a) {
  // maybe check id
  this.otherFieldToBeMerged = a.getFieldToMerge();
}
}

class MyAssocation {
private long id;
private String fieldToMerge;

// getters/setters
}

You can make the MyAssociation class and the setMyAssociation method package private so that it's only visible within the Mapper scope.

I might have missed it but I don't know anything in MyBatis that can merge the results of two selects.

Dridi
http://www.zenika.com/
Reply all
Reply to author
Forward
0 new messages