logo       


Re: Confused with groupBy: msg#00467

Subject: Re: Confused with groupBy
Larry Meadors writes:
...

The groupBy attribute is used to deal with the "N+1" selects problem.
The "N+1 Selects" problem is caused by trying to load child records
that are related to a list of parent records. So, if you run one query
to get the parent records, and there are some number "N" of them, then
you have to run "N" more queries to get the child records for the
parent records resulting in "N+1 selects".

Yes I FULLY understand the above


Here is another example that does an Account -> Order -> OrderItem
mapping using this technique: <resultMap id="ResultAccountInfoNMap" class="AccountInfo" groupBy="account.accountId" >
    <result property="account.accountId" column="accountId" />
    <result property="orderList" resultMap="Ch7.ResultOrderInfoNMap" />
</resultMap> <resultMap id="ResultOrderInfoNMap" class="OrderInfo" groupBy="order.orderId" >
    <result property="order.orderId" column="orderId" />
    <result property="orderItemList" resultMap="Ch7.ResultOrderItemNMap" />
</resultMap>
  <resultMap id="ResultOrderItemNMap" class="OrderItem">
    <result property="orderId" column="orderId" />
    <result property="orderItemId" column="orderItemId"  />
</resultMap>
  <select id="getAccountInfoListN" resultMap="ResultAccountInfoNMap">
    select
      account.accountId as accountid,
      orders.orderid as orderid,
      orderitem.orderitemid as orderitemid
    from account
    join orders on account.accountId = orders.accountId
    join orderitem on orders.orderId = orderitem.orderId
    order by accountId, orderid, orderitemid
  </select>

I may be a little dense here - can I just confirm. In class "AccountInfo", you have a property called "account" which is itself an object of some class(doesn't precisely matter, the class definition for AccountInfo will have imported the definition). This sub object has a property called "accountID" (and similarly for "order"). [only asking because this seems to make the example slightly more complex than it needs for explanation, and I am just making sure I understand correctly].

Does that make it any clearer?


Well... I still don't understand exactly what the groupBy attribute is actually saying here. Let me run one proposition by you and see if I have it right. Is it saying account.accountID is the common field that the query is joined on, and therefore there will be a lot of records where this will be a common factor - and to take all of them and use them to only create a single instance of class AccountInfo and to populate orderList with all the variants of this particular common field (and of course a similar position this with OrderInfo and orderItemList)? If that right, then I think I've got it. I know when I need to use it. If not ... ... then you will have to try again:-(



--
Alan Chandler
alan@xxxxxxxxxxxxxxxxxxxxx




Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
Search:
Java, servers, webhosting, windows, cisco ...
more...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe