java - Mapping same table twice in different associations in MyBatis -


i have 6 tables structured (there more descriptive example @ bottom):

a

every item related 1 item in b , 1 item in c.

aid | bid | cid 

b

every item related multiple items in d.

bid 

c

every item related multiple items in d.

cid 

d

every item related multiple items in b , c.

did 

e

maps items in b items in d.

bid | did 

f

maps items in c items in d.

cid | did 

now i'm trying write mapper in mybatis maps items in table a. mapper has association mappers of table b , c, , mappers of tables b , c both have collection containing items of table d.

individually mapping either b or c items of table d isn't problem, since simple join operation using either e or f enough. however, problem arises when trying map perspective of table a. table associated both table b , c, , both associated table d, don't know how let mappers of b , c distinguish between items in table d meant them.

basically, i'm trying join d b , c perspective of a's mapper.

is there way join table d twice in mybatis, whilst keeping distinction between 2 joins mappers of b , c can distinguish between two?

thanks help!

edit

here's small example more descriptive names.

houses

houseid | livingroomid | kitchenid 1       | 1            | 1 

livingrooms

livingroomid 1 

kitchens

kitchenid 1 

furniture

furnitureid | furniturename 1           | couch 2           | lamp 3           | fridge 

livingroomfurniture

livingroomid | furnitureid 1            | 1 1            | 2 

kitchenfurniture

kitchenid | furnitureid 1         | 2 1         | 3 

my mappers currently:

mapper.xml

<?xml version="1.0" encoding="utf-8" ?> <!doctype mapper public "-//mybatis.org//dtd mapper 3.0//en" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper>     <resultmap type="com.project.models.house.house" id="houseresult">         <id             property="id"           column="houseid" />         <association    property="livingroom"   resultmap="livingroomresult" />         <association    property="kitchen"      resultmap="kitchenresult" />     </resultmap>      <resultmap type="com.project.models.livingroom.livingroom" id="livingroomresult">         <id             property="id"           column="livingroomid" />         <collection     property="furniture"    resultmap="furnitureresult" />     </resultmap>      <resultmap type="com.project.models.kitchen.kitchen" id="kitchenresult">         <id             property="id"           column="kitchenid" />         <collection     property="furniture"    resultmap="furnitureresult" />     </resultmap>      <resultmap type="com.project.models.furniture.furniture" id="furnitureresult">         <id             property="id"           column="furnitureid" />         <result         property="name"         column="furniturename" />     </resultmap>      <select id="getallhouses" resultmap="houseresult">         select           houses.houseid,           houses.livingroomid,           houses.kitchenid          houses          -- living room         inner join livingrooms on livingrooms.livingroomid = houses.livingroomid          -- kitchen         inner join kitchens on kitchens.kitchenid = kitchens.kitchenid          -- here somehow join furniture both living room , kitchen?     </select> </mapper> 

you have join d both tables b , c alias them in accordingly.

let's bd table d joined b , cd.

now if want same resultmap of table d both aliased table (bd , cd), can this:

select bd.did bd_did, cd.did cd_did 

and if have not come across column_prefix property of result maps how resultmap look

<collection type="d" resultmap="d" column_prefix="bd_" /> 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -