ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jozef Hribik <jozef.hri...@apsoft.sk>
Subject Re: [Fwd: How to pass a parameter to collection property?]
Date Mon, 05 Dec 2005 14:15:16 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Once again 'Thank you', I have tried it too, but i have problems like
those described in JIRA:<br>
<>(N + 1) solution does not yield same results as lazy loading solution<br>
<a class="moz-txt-link-freetext" href="http://issues.apache.org/jira/browse/IBATIS-69">http://issues.apache.org/jira/browse/IBATIS-69</a><br>
 <br>
I have no more time to experiment what is wrong in my mapping.<br>
I will stay by ugly-but-functional 1+N queries solution.<br>
</><br>
<br>
Jeff Butler wrote:
<blockquote
 cite="midc593b8750512050550h747f8e9dgcb5b7706ef6919a7@mail.gmail.com"
 type="cite">
  <div>Ahh - I see.  This is a classic example of the N+1 selects
problem.  iBATIS has a good solution: use an SQL join and the iBATIS
groupBy feature.  This link should help:</div>
  <div> </div>
  <div><a
 href="http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+around+the+N+Plus+1+selects+problem">http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+around+the+N+Plus+1+selects+problem
  </a></div>
  <div> </div>
  <div>Jeff Butler</div>
  <div><br>
 </div>
  <div><span class="gmail_quote">On 12/5/05, <b
 class="gmail_sendername">Jozef Hribik</b> &lt;<a
 href="mailto:jozef.hribik@apsoft.sk">jozef.hribik@apsoft.sk</a>&gt;
wrote:</span>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left:
1ex;">Thank
you Jeff, i am using your solution already, but i want to get <b>_categories_with_products_</b>
in single step.
    <span class="q"><br>
 <br>
    <div>Map map = new HashMap();</div>
    <div>map.put("parameterY", parameterY);</div>
    </span>
    <div>
    <div>map.put("parameterX", parameterX);</div>
    <div>List results = sqlMap.queryForList("getCategory", map);</div>
    </div>
    <br>
&lt;statement id="getCategory" parameterClass="int"
resultMap="get-category-result"&gt;<br>
select * from CATEGORY where CAT_DESCRIPTION like  '%$
    <b>parameterY</b>$%'<br>
&lt;/statement&gt;<span class="q"><br>
    <br>
&lt;statement id="getProductsByCatId" parameterClass="int"
resultMap="get-product-result"&gt; <br>
select * from PRODUCT where PRD_CAT_ID = #value# and PRD_PRICE = <b>#parameterX#</b><br>
&lt;/statement&gt;<br>
    <br>
    </span>Is it possible or is it a new feature request ?
    <div><span class="e" id="q_107f9eeedf5ba7cb_5"><br>
    <br>
    <br>
    <br>
Jeff Butler wrote:<br>
    <blockquote
 cite="http://midc593b8750512020724h4dcfcf81lc2e3d5369b111007@mail.gmail.com"
 type="cite">
      <div>Here's how to do it with a map:</div>
      <div> </div>
      <div>Map map = new HashMap();</div>
      <div>map.put("parameterY", parameterY);</div>
      <div>
      <div>map.put("parameterX", parameterX);</div>
      <div>List results = sqlMap.queryForList("getProductsByCatId",
map);</div>
      </div>
      <div> </div>
      <div> </div>
      <div>&lt;<strong>select</strong> id="getProductsByCatId"
parameterClass="<strong>java.util.Map</strong>"
resultMap="get-product-result"&gt;<br>
select * from PRODUCT where PRD_CAT_ID = #<strong>
parameterY</strong># and PRD_PRICE = <b>#parameterX#</b><br>
&lt;/<strong>select</strong>&gt;<br>
 </div>
      <div>You could also do it with a POJO as your parameter class
(which is preferred) - the properties in the select statement
correspond to properties in your POJO.</div>
      <div> </div>
      <div>Jeff Butler<br>
      <br>
 </div>
      <div><span class="gmail_quote">On 12/2/05, <b
 class="gmail_sendername">Jozef Hribik</b> &lt;<a
 onclick="return top.js.OpenExtLink(window,event,this)"
 href="mailto:jozef.hribik@apsoft.sk" target="_blank">jozef.hribik@apsoft.sk
      </a>&gt; wrote:</span>
      <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left:
1ex;">I
would like to pass an additional parameter to filter a collection
property.<br>
I will use an example from iBATIS-SqlMaps-2.pdf, page 27.<br>
 <br>
How can i select a category with products with certain price specified
by parameterX?<br>
 <br>
&lt;resultMap id="get-category-result"
class="com.ibatis.example.Category
"&gt;<br>
&lt;result property="id" column="CAT_ID"/&gt; <br>
&lt;result property="description" column="CAT_DESCRIPTION"/&gt;<br>
&lt;result property="productList" column="CAT_ID"
select="getProductsByCatId"/&gt;
        <br>
&lt;/resultMap&gt;<br>
        <br>
&lt;statement id="getProductsByCatId" parameterClass="int"
resultMap="get-product-result"&gt; <br>
select * from PRODUCT where PRD_CAT_ID = #value# and PRD_PRICE = <b>#parameterX#</b><br>
&lt;/statement&gt;<br>
        <br>
Thanks<br>
        <span>Jozef<br>
        </span></blockquote>
      </div>
      <br>
    </blockquote>
    <br>
    </span></div>
  </blockquote>
  </div>
  <br>
</blockquote>
<br>
</body>
</html>

Mime
View raw message