You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by vinays84 <vi...@hotmail.com> on 2007/07/13 02:30:07 UTC

One Bean, multiple queries

I'm curious if iBatis can somehow handle mapping results to an existing
object or whether it must always create a new result object. Consider a
situation where a few queries are need to define a bean (for example a
specific report where the main data will have multiple rows and called from
query A, and the summary information will be one row and called from query
B). If a JavaBean class is created capable of storing data from all the
queries, the DAO would need to call each query, creating multiple instances
of the bean, each with data the other one desires. The developer would then
be tasked with manually merging all the data in to one main bean, which
could be tedious if each query contains a lot of data. Can iBatis handle
grabbing a partially populated bean and fully populating it from another
query? If not, how would one best tackle the example situation I described?
Thanks!
-- 
View this message in context: http://www.nabble.com/One-Bean%2C-multiple-queries-tf4071676.html#a11571412
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: One Bean, multiple queries

Posted by Clinton Begin <cl...@gmail.com>.
One bean, to rule them all....

LOL.  K, yeah, just pass it in to queryForObject as the last parameter.
queryForObject("statement", param, targetObject)

can't remember if we deprecated that ... :-/


Clinton

On 7/26/07, Vadim Grinshpun <va...@ll.mit.edu> wrote:
>
> the result maps may be what you need; but if you truly need to populate an
> object that has already been constructed,
> I believe there's an overloaded version of queryForObject that takes an
> additional parameter of an object instance to be modified. **
>
> sachin.x.mahajan@jpmchase.com wrote:
>
>
> Hi Vinay,
>
> Checkout this result map in which category is a member of Product. This
> way you can bind queries to produce single result.
> I hope this is what you have asked for.
> This sample if from the IBatis tutorial.
>
>
> <resultMap id="get-product-result" class="com.ibatis.example.Product">
> <result property="id" column="PRD_ID"/>
> <result property="description" column="PRD_DESCRIPTION"/>
> <result property="category" column="PRD_CAT_ID" select="getCategory"/>
> </resultMap>
> <resultMap id="get-category-result" class="com.ibatis.example.Category">
> <result property="id" column="CAT_ID"/>
> <result property="description" column="CAT_DESCRIPTION"/>
> </resultMap>
> <statement id="getProduct" parameterClass="int"
> resultMap="get-product-result">
> select * from PRODUCT where PRD_ID = #value#
> </statement>
> <statement id="getCategory" parameterClass="int"
> resultMap="get-category-result">
> select * from CATEGORY where CAT_ID = #value#
> </statement>
>
> Regards,
> Sachin
>
>
>
>   *vinays84 <vi...@hotmail.com> <vi...@hotmail.com>*
>
> 07/13/2007 06:00 AM   Please respond to
> user-java@ibatis.apache.org
>
>    To
> user-java@ibatis.apache.org  cc
>
>  Subject
> One Bean, multiple queries
>
>
>
>
>
>
>
> I'm curious if iBatis can somehow handle mapping results to an existing
> object or whether it must always create a new result object. Consider a
> situation where a few queries are need to define a bean (for example a
> specific report where the main data will have multiple rows and called
> from
> query A, and the summary information will be one row and called from query
> B). If a JavaBean class is created capable of storing data from all the
> queries, the DAO would need to call each query, creating multiple
> instances
> of the bean, each with data the other one desires. The developer would
> then
> be tasked with manually merging all the data in to one main bean, which
> could be tedious if each query contains a lot of data. Can iBatis handle
> grabbing a partially populated bean and fully populating it from another
> query? If not, how would one best tackle the example situation I
> described?
> Thanks!
> --
> View this message in context:
> http://www.nabble.com/One-Bean%2C-multiple-queries-tf4071676.html#a11571412
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com<http://nabble.com/>
> .
>
>
>
> ------------------------------
>
> This communication is for informational purposes only. It is not intended
> as an offer or solicitation for the purchase or sale of any financial
> instrument or as an official confirmation of any transaction. All market
> prices, data and other information are not warranted as to completeness or
> accuracy and are subject to change without notice. Any comments or
> statements made herein do not necessarily reflect those of JPMorgan Chase &
> Co., its subsidiaries and affiliates. This transmission may contain
> information that is privileged, confidential, legally privileged, and/or
> exempt from disclosure under applicable law. If you are not the intended
> recipient, you are hereby notified that any disclosure, copying,
> distribution, or use of the information contained herein (including any
> reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any
> attachments are believed to be free of any virus or other defect that might
> affect any computer system into which it is received and opened, it is the
> responsibility of the recipient to ensure that it is virus free and no
> responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and
> affiliates, as applicable, for any loss or damage arising in any way from
> its use. If you received this transmission in error, please immediately
> contact the sender and destroy the material in its entirety, whether in
> electronic or hard copy format. Thank you. Please refer to
> http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK
> legal entities.
>
>
>

Re: One Bean, multiple queries

Posted by Vadim Grinshpun <va...@ll.mit.edu>.
the result maps may be what you need; but if you truly need to populate 
an object that has already been constructed,
I believe there's an overloaded version of queryForObject that takes an 
additional parameter of an object instance to be modified. **

sachin.x.mahajan@jpmchase.com wrote:
>
> Hi Vinay,
>
> Checkout this result map in which category is a member of Product. 
> This way you can bind queries to produce single result.
> I hope this is what you have asked for.
> This sample if from the IBatis tutorial.
>
>
> <resultMap id=”get-product-result” class=”com.ibatis.example.Product”>
> <result property=”id” column=”PRD_ID”/>
> <result property=”description” column=”PRD_DESCRIPTION”/>
> <result property=”category” column=”PRD_CAT_ID” select=”getCategory”/>
> </resultMap>
> <resultMap id=”get-category-result” class=”com.ibatis.example.Category”>
> <result property=”id” column=”CAT_ID”/>
> <result property=”description” column=”CAT_DESCRIPTION”/>
> </resultMap>
> <statement id=”getProduct” parameterClass=”int” 
> resultMap=”get-product-result”>
> select * from PRODUCT where PRD_ID = #value#
> </statement>
> <statement id=”getCategory” parameterClass=”int” 
> resultMap=”get-category-result”>
> select * from CATEGORY where CAT_ID = #value#
> </statement>
>
> Regards,
> Sachin
>
>
>
> *vinays84 <vi...@hotmail.com>*
>
> 07/13/2007 06:00 AM
> Please respond to
> user-java@ibatis.apache.org
>
>
> 	
> To
> 	user-java@ibatis.apache.org
> cc
> 	
> Subject
> 	One Bean, multiple queries
>
>
>
> 	
>
>
>
>
>
>
> I'm curious if iBatis can somehow handle mapping results to an existing
> object or whether it must always create a new result object. Consider a
> situation where a few queries are need to define a bean (for example a
> specific report where the main data will have multiple rows and called 
> from
> query A, and the summary information will be one row and called from query
> B). If a JavaBean class is created capable of storing data from all the
> queries, the DAO would need to call each query, creating multiple 
> instances
> of the bean, each with data the other one desires. The developer would 
> then
> be tasked with manually merging all the data in to one main bean, which
> could be tedious if each query contains a lot of data. Can iBatis handle
> grabbing a partially populated bean and fully populating it from another
> query? If not, how would one best tackle the example situation I 
> described?
> Thanks!
> -- 
> View this message in context: 
> http://www.nabble.com/One-Bean%2C-multiple-queries-tf4071676.html#a11571412
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
>
> ------------------------------------------------------------------------
>
> This communication is for informational purposes only. It is not 
> intended as an offer or solicitation for the purchase or sale of any 
> financial instrument or as an official confirmation of any 
> transaction. All market prices, data and other information are not 
> warranted as to completeness or accuracy and are subject to change 
> without notice. Any comments or statements made herein do not 
> necessarily reflect those of JPMorgan Chase & Co., its subsidiaries 
> and affiliates. This transmission may contain information that is 
> privileged, confidential, legally privileged, and/or exempt from 
> disclosure under applicable law. If you are not the intended 
> recipient, you are hereby notified that any disclosure, copying, 
> distribution, or use of the information contained herein (including 
> any reliance thereon) is STRICTLY PROHIBITED. Although this 
> transmission and any attachments are believed to be free of any virus 
> or other defect that might affect any computer system into which it is 
> received and opened, it is the responsibility of the recipient to 
> ensure that it is virus free and no responsibility is accepted by 
> JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, 
> for any loss or damage arising in any way from its use. If you 
> received this transmission in error, please immediately contact the 
> sender and destroy the material in its entirety, whether in electronic 
> or hard copy format. Thank you. Please refer to 
> http://www.jpmorgan.com/pages/disclosures for disclosures relating to 
> UK legal entities.
>


Re: One Bean, multiple queries

Posted by sa...@jpmchase.com.
Hi Vinay,

Checkout this result map in which category is a member of Product. This 
way you can bind queries to produce single result.
I hope this is what you have asked for.
This sample if from the IBatis tutorial.


<resultMap id=”get-product-result” class=”com.ibatis.example.Product”>
<result property=”id” column=”PRD_ID”/>
<result property=”description” column=”PRD_DESCRIPTION”/>
<result property=”category” column=”PRD_CAT_ID” select=”getCategory”/>
</resultMap>
<resultMap id=”get-category-result” class=”com.ibatis.example.Category”>
<result property=”id” column=”CAT_ID”/>
<result property=”description” column=”CAT_DESCRIPTION”/>
</resultMap>
<statement id=”getProduct” parameterClass=”int” 
resultMap=”get-product-result”>
select * from PRODUCT where PRD_ID = #value#
</statement>
<statement id=”getCategory” parameterClass=”int” 
resultMap=”get-category-result”>
select * from CATEGORY where CAT_ID = #value#
</statement>

Regards,
Sachin




vinays84 <vi...@hotmail.com> 
07/13/2007 06:00 AM
Please respond to
user-java@ibatis.apache.org


To
user-java@ibatis.apache.org
cc

Subject
One Bean, multiple queries







I'm curious if iBatis can somehow handle mapping results to an existing
object or whether it must always create a new result object. Consider a
situation where a few queries are need to define a bean (for example a
specific report where the main data will have multiple rows and called 
from
query A, and the summary information will be one row and called from query
B). If a JavaBean class is created capable of storing data from all the
queries, the DAO would need to call each query, creating multiple 
instances
of the bean, each with data the other one desires. The developer would 
then
be tasked with manually merging all the data in to one main bean, which
could be tedious if each query contains a lot of data. Can iBatis handle
grabbing a partially populated bean and fully populating it from another
query? If not, how would one best tackle the example situation I 
described?
Thanks!
-- 
View this message in context: 
http://www.nabble.com/One-Bean%2C-multiple-queries-tf4071676.html#a11571412

Sent from the iBATIS - User - Java mailing list archive at Nabble.com.






-----------------------------------------
This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to UK legal entities.