Re: Please help with mapping Ibatis

2009-03-31 Thread Ingmar Lötzsch
 I have a class
 
 public class Part{
 private Integer id; 
 private String name;
 private Bar bar;
 
 
 getters/setters 
 }
 
 I have a mapping for part and for there part I am adding aliases for column
 names after join.
 
 I am sure it is not correct way to do it. Please advice how to do correct
 way.
 
 Current mapping looks like
 
   resultMap id=part
 class=domain.Part
 result property=name column=name /
 result property=id column=id /
 result property=bar resultMap=part.bar /
   /resultMap
 
 
   resultMap id=otherPart
 class=domain.Part
 result property=name column=otherName /
 result property=id column=otherId /
 result property=bar resultMap=part.otherBar /
   /resultMap
 
 SQL
 
 select
 p1.id,
 p1.name,
 b.*,
 p1.id as otherId,
 p1.name as otherName
 from PART p1 
 join BAR b on p1.id=b.p1Id
 join PART p2 on p2.id=b.p2Id
 
 
 Basically question is
 How to map the objects if during the querying the same table is join more
 then one time?

That depends on the object graph, you want to get. An entity
relationship diagram or class diagram would be helpful. Supposed you have

Bar 1 -- 2 Part

and

Bar
-part1 : Part
-part2 : Part

and want to get a list of bars, you can do the following

resultMap id=bar.result resultClass=domain.Bar
result property=part1 resultMap=part/
result property=part2 resultMap=otherPart/
...
/resultMap

select id=bar.selectAll resultMap=bar.result
select
p1.id,
p1.name,
b.*,
p1.id as otherId,
p1.name as otherName
from PART p1
join BAR b on p1.id=b.p1Id
join PART p2 on p2.id=b.p2Id
/select

ListBar list = getSqlMapClientTemplate().queryForList(bar.selectAll);

Ingmar


Re: Please help with mapping Ibatis

2009-03-31 Thread AlexElba

So only way is to do with aliases?

No way I can reuse the already mapped dto other then remap it?



Ingmar Lötzsch wrote:
 
 I have a class
 
 public class Part{
 private Integer id; 
 private String name;
 private Bar bar;
 
 
 getters/setters 
 }
 
 I have a mapping for part and for there part I am adding aliases for
 column
 names after join.
 
 I am sure it is not correct way to do it. Please advice how to do correct
 way.
 
 Current mapping looks like
 
   resultMap id=part
 class=domain.Part
 result property=name column=name /
 result property=id column=id /
 result property=bar resultMap=part.bar /
   /resultMap
 
 
   resultMap id=otherPart
 class=domain.Part
 result property=name column=otherName /
 result property=id column=otherId /
 result property=bar resultMap=part.otherBar /
   /resultMap
 
 SQL
 
 select
 p1.id,
 p1.name,
 b.*,
 p1.id as otherId,
 p1.name as otherName
 from PART p1 
 join BAR b on p1.id=b.p1Id
 join PART p2 on p2.id=b.p2Id
 
 
 Basically question is
 How to map the objects if during the querying the same table is join more
 then one time?
 
 That depends on the object graph, you want to get. An entity
 relationship diagram or class diagram would be helpful. Supposed you have
 
 Bar 1 -- 2 Part
 
 and
 
 Bar
 -part1 : Part
 -part2 : Part
 
 and want to get a list of bars, you can do the following
 
 resultMap id=bar.result resultClass=domain.Bar
   result property=part1 resultMap=part/
   result property=part2 resultMap=otherPart/
 ...
 /resultMap
 
 select id=bar.selectAll resultMap=bar.result
   select
   p1.id,
   p1.name,
   b.*,
   p1.id as otherId,
   p1.name as otherName
   from PART p1
   join BAR b on p1.id=b.p1Id
   join PART p2 on p2.id=b.p2Id
 /select
 
 ListBar list = getSqlMapClientTemplate().queryForList(bar.selectAll);
 
 Ingmar
 
 

-- 
View this message in context: 
http://www.nabble.com/Please-help-with-mapping-Ibatis-tp22796133p22805239.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.



Re: Please help with mapping Ibatis

2009-03-31 Thread Ingmar Lötzsch
 So only way is to do with aliases?
 
 No way I can reuse the already mapped dto other then remap it?

You can use the select attribute instead of resultMap. You can combine
this with lazy loading.

Ingmar