• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

iBatis resultMap groupBy Question

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Given parent table : ORDER_ITEMS
related to child table : ITEM_SHIPMENT by two keys ORDER_ID and ORDER_LINE_ID (both the keys are required to establish a precise parent-child relation)
if we want to get a list of child table a store in a parent object in iBatis, we do :
<resultMap id="parent" class="Parent" groupBy="parentId">

But in this case, we have 2 keys, so I do not know how to do it.
Can groupBy be mapped to another class that can have both these keys as members ?
 
aditee sharma
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
correction :
......
if we want to fetch child records and store in parent object
.....
 
aditee sharma
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is ther no body who has faced this situation ?
How do we put a composite key in groupBy of Ibatis resultMap
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi aditee,
It seems you are facing N+1 problem in iBatis...Which is fully solvable
Below code snipet will solve your problem
This is from iBatis Developer guide



myList is a List of beans containing type
"com.ibatis.example.Category". Each object in that List will have a "productList" property that is also a List
populated from the same query, but using the "productResult" result map to populate the beans in the child
list. So, you end up with a list containing sub-lists, and only one database query is executed and both child and parent list are get popultaed as expected..

Cheers,
Dhananjay
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic