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 Rick <ri...@gmail.com> on 2008/11/17 16:56:51 UTC
Am I missing something really simple? Way to avoid adding all props in a map if I decide to add one extra collection to pojo
Hopefully I'm just being a newb and missing something simple. It's
been a while since I worked with iBATIS:)...
My column names and pojo names are the same, so typically I don't even
need a result map created to map my properties (I can just map my
resultClass to the query). Where things break down though is if I want
to nest a collection of another object in one of my pojos. For example
in the code below BusinessEntity can have "Associates" so I've added a
List<Associate> field to my BusinessEntity pojo. What I'd love to do
now is somehow get my BusinessEntity populated and the nested
Associate lists populated *WITHOUT* having to go through and declare
EVERY SINGLE property in a Map (since my fields match up fine to the
columns.) It seems though that I can't do this? Am I missing an easy
way to avoid this? I wish I could do something like:
<!-- populated all properties on the BusinessEntity class if you can!!!! --->
<resultMap id="beMap2" class="BusinessEntity" groupBy="businessEntityID">
<!-- directly map a *** resultClass ! ***--->
<result property="associates" resultClass="BusinessEntity.assMap2"/>
</resultMap>
(Is there a work around?)
Instead of the above I'm currently having to do:
<!-- example poulating the Value Objects -->
<resultMap id="beMap2" class="BusinessEntity" groupBy="businessEntityID">
<result property="businessEntityID" column="businessEntityID"/>
<result property="name" column="name"/>
...// *** having to map all my other props?
<result property="addressLine1" column="addressLine1"/>
<result property="associates" resultMap="BusinessEntity.assMap2"/>
</resultMap>
<resultMap id="assMap2" class="com.nielsen.ondp.persistence.model.Associate">
<result property="firstName" column="firstName"/>
<result property="lastName" column="lastName"/>
...// *** having to map all my other props?
</resultMap>
the simple query:
<select id="findBEsWithAssociates2" resultMap="beMap2" cacheModel="beCache">
SELECT be.*, a.*
FROM NPPBusinessEntity be, NPPAssociate a
WHERE a.businessEntityID = be.businessEntityID ORDER BY be.businessEntityID
</select>
Re: Am I missing something really simple? Way to avoid adding all props in a map if I decide to add one extra collection to pojo
Posted by Rick <ri...@gmail.com>.
On Tue, Nov 18, 2008 at 12:44 PM, Kai Grabfelder <no...@kinokai.de> wrote:
> I don't think that this is currently possible. I don't really mind writing result maps, as I'm generating most
> of them with abator.
Yea, I'm currently doing the same (using ibator to create my
mappings), but I still think it would be nice to use a regular pojo
when possible - in other words "map the columns to the properties" if
you can. It obviously works inline, I'd just like push it up a bit to
be able to a result map so that I can add a few more fields -
collections, or another embedded pojo.
Re: Am I missing something really simple? Way to avoid adding all
props in a map if I decide to add one extra collection to pojo
Posted by Kai Grabfelder <no...@kinokai.de>.
I don't think that this is currently possible. I don't really mind writing result maps, as I'm generating most
of them with abator.
If you really need this feature feel free to create a jire issue and attach a patch against the current iBATIS
trunk to it.
Regards
Kai
--- Original Nachricht ---
Absender: Rick
Datum: 18.11.2008 17:22
> I sent this tot he wrong list before, so I'm resending it. I think it
> would be a huge plus for ibatis. I don't mind digging into the source
> code... would it be a really tough fix? To modify result maps to allow
> them being based on result classes? Has this been brought up before.
> Just curious.
>
> To sum up if you don't read the original email - I can easily get this
> back in one query and notice how I don't need every property mapped.
> (The current way, you need an Address map of every property and and
> Associate with every property, when all I want to do is map up the
> column names directly to the objects)
>
> <!-- populated all properties on the BusinessEntity class if you can,
> without mapping them !!!! --->
> <resultMap id="beResult" class="BusinessEntity" groupBy="businessEntityID">
> <!-- directly map *** resultClasses not maps ! ***--->
> <result property="associates" resultClass="BusinessEntity"/>
> <result property="address" resultClass="Address"/>
> </resultMap>
>
> for:
> BusinessEntity {
> String name;
> String abbreviation;
> Integer id;
> //..etc
> Address address
> List<Associate> associates
> }
>
>
> On Mon, Nov 17, 2008 at 10:56 AM, Rick <ri...@gmail.com> wrote:
>> Hopefully I'm just being a newb and missing something simple. It's
>> been a while since I worked with iBATIS:)...
>>
>> My column names and pojo names are the same, so typically I don't even
>> need a result map created to map my properties (I can just map my
>> resultClass to the query). Where things break down though is if I want
>> to nest a collection of another object in one of my pojos. For example
>> in the code below BusinessEntity can have "Associates" so I've added a
>> List<Associate> field to my BusinessEntity pojo. What I'd love to do
>> now is somehow get my BusinessEntity populated and the nested
>> Associate lists populated *WITHOUT* having to go through and declare
>> EVERY SINGLE property in a Map (since my fields match up fine to the
>> columns.) It seems though that I can't do this? Am I missing an easy
>> way to avoid this? I wish I could do something like:
>>
>> <!-- populated all properties on the BusinessEntity class if you can!!!! --->
>> <resultMap id="beMap2" class="BusinessEntity" groupBy="businessEntityID">
>> <!-- directly map a *** resultClass ! ***--->
>> <result property="associates" resultClass="BusinessEntity"/>
>> </resultMap>
>>
>> (Is there a work around?)
>>
>> Instead of the above I'm currently having to do:
>>
>> <!-- example poulating the Value Objects -->
>> <resultMap id="beMap2" class="BusinessEntity" groupBy="businessEntityID">
>> <result property="businessEntityID" column="businessEntityID"/>
>> <result property="name" column="name"/>
>>
>> ...// *** having to map all my other props?
>>
>> <result property="addressLine1" column="addressLine1"/>
>> <result property="associates" resultMap="BusinessEntity.assMap2"/>
>> </resultMap>
>>
>> <resultMap id="assMap2" class="com.nielsen.ondp.persistence.model.Associate">
>> <result property="firstName" column="firstName"/>
>> <result property="lastName" column="lastName"/>
>>
>> ...// *** having to map all my other props?
>>
>> </resultMap>
>>
>> the simple query:
>>
>> <select id="findBEsWithAssociates2" resultMap="beMap2" cacheModel="beCache">
>> SELECT be.*, a.*
>> FROM NPPBusinessEntity be, NPPAssociate a
>> WHERE a.businessEntityID = be.businessEntityID ORDER BY be.businessEntityID
>> </select>
>>
>
>
>
Re: Am I missing something really simple? Way to avoid adding all props in a map if I decide to add one extra collection to pojo
Posted by Rick <ri...@gmail.com>.
On Tue, Nov 18, 2008 at 6:31 PM, Raymond McDermott <ra...@mcdermott.be> wrote:
>
> Chalk up one more disappointed user.
Hey, I'm not a disappointed user:) Just thought it might be cool to
allow the functionality.
Re: Am I missing something really simple? Way to avoid adding all props in a map if I decide to add one extra collection to pojo
Posted by Raymond McDermott <ra...@mcdermott.be>.
Sorry Rick I misunderstood. You are right that is clearly limiting.
I expected nested classes to have the same automatic reflection style
processing.
Chalk up one more disappointed user.
2008/11/18 Rick <ri...@gmail.com>
> On Tue, Nov 18, 2008 at 3:43 PM, Raymond McDermott <ra...@mcdermott.be>
> wrote:
> > iBatis supports automatically mapping in beans where the property names
> > match the getters/setters so you are in luck ;-)
>
> I understand that but that ONLY works for when you are mapping one
> statement to a class.
>
> Look at that example on page 33 you mention. It maps the result set to
> "Product" but if you also wanted to return "List<ProductPart>
> productParts" ?
> How would you do it? You'd have to create a resultMap and apparently
> add EVERY product property to the map just so you can add the
> collection productParts to your result map. And on top of that you
> also will need a map of every property for your ProductPart because
> (as far as I can tell) you can't map a result property to a Class -
> only a map?
>
> <resultMap id="productMap" class="Product" groupBy="productID">
> <!-- ALL THE OTHER PROPS? --->
> <!-- can't do this below bc can' map producParts to a 'resultClass'
> --->
> <result property="productParts" resultClass="ProductPart"/>
> </resultMap>
>
> Obviously the above isn't a big deal if just returning one product
> since you could just make two queries, but if you want a list of all
> products and their product parts, you now have a different situation
> and you seem to HAVE to have all properties in a result map.
>
> It just seems verbose to have to have all those mapped properties
> defined just to allow for some nesting of other objects.
>
--
Ray McDermott
GSM 047/32.53.854
Re: Am I missing something really simple? Way to avoid adding all props in a map if I decide to add one extra collection to pojo
Posted by Rick <ri...@gmail.com>.
On Tue, Nov 18, 2008 at 3:43 PM, Raymond McDermott <ra...@mcdermott.be> wrote:
> iBatis supports automatically mapping in beans where the property names
> match the getters/setters so you are in luck ;-)
I understand that but that ONLY works for when you are mapping one
statement to a class.
Look at that example on page 33 you mention. It maps the result set to
"Product" but if you also wanted to return "List<ProductPart>
productParts" ?
How would you do it? You'd have to create a resultMap and apparently
add EVERY product property to the map just so you can add the
collection productParts to your result map. And on top of that you
also will need a map of every property for your ProductPart because
(as far as I can tell) you can't map a result property to a Class -
only a map?
<resultMap id="productMap" class="Product" groupBy="productID">
<!-- ALL THE OTHER PROPS? --->
<!-- can't do this below bc can' map producParts to a 'resultClass' --->
<result property="productParts" resultClass="ProductPart"/>
</resultMap>
Obviously the above isn't a big deal if just returning one product
since you could just make two queries, but if you want a list of all
products and their product parts, you now have a different situation
and you seem to HAVE to have all properties in a result map.
It just seems verbose to have to have all those mapped properties
defined just to allow for some nesting of other objects.
Re: Am I missing something really simple? Way to avoid adding all props in a map if I decide to add one extra collection to pojo
Posted by Raymond McDermott <ra...@mcdermott.be>.
iBatis supports automatically mapping in beans where the property names
match the getters/setters so you are in luck ;-)
See page 33 of the manual for 'implicit result maps'
2008/11/18 Rick <ri...@gmail.com>
> I sent this tot he wrong list before, so I'm resending it. I think it
> would be a huge plus for ibatis. I don't mind digging into the source
> code... would it be a really tough fix? To modify result maps to allow
> them being based on result classes? Has this been brought up before.
> Just curious.
>
> To sum up if you don't read the original email - I can easily get this
> back in one query and notice how I don't need every property mapped.
> (The current way, you need an Address map of every property and and
> Associate with every property, when all I want to do is map up the
> column names directly to the objects)
>
> <!-- populated all properties on the BusinessEntity class if you can,
> without mapping them !!!! --->
> <resultMap id="beResult" class="BusinessEntity" groupBy="businessEntityID">
> <!-- directly map *** resultClasses not maps ! ***--->
> <result property="associates" resultClass="BusinessEntity"/>
> <result property="address" resultClass="Address"/>
> </resultMap>
>
> for:
> BusinessEntity {
> String name;
> String abbreviation;
> Integer id;
> //..etc
> Address address
> List<Associate> associates
> }
>
>
> On Mon, Nov 17, 2008 at 10:56 AM, Rick <ri...@gmail.com> wrote:
> > Hopefully I'm just being a newb and missing something simple. It's
> > been a while since I worked with iBATIS:)...
> >
> > My column names and pojo names are the same, so typically I don't even
> > need a result map created to map my properties (I can just map my
> > resultClass to the query). Where things break down though is if I want
> > to nest a collection of another object in one of my pojos. For example
> > in the code below BusinessEntity can have "Associates" so I've added a
> > List<Associate> field to my BusinessEntity pojo. What I'd love to do
> > now is somehow get my BusinessEntity populated and the nested
> > Associate lists populated *WITHOUT* having to go through and declare
> > EVERY SINGLE property in a Map (since my fields match up fine to the
> > columns.) It seems though that I can't do this? Am I missing an easy
> > way to avoid this? I wish I could do something like:
> >
> > <!-- populated all properties on the BusinessEntity class if you can!!!!
> --->
> > <resultMap id="beMap2" class="BusinessEntity" groupBy="businessEntityID">
> > <!-- directly map a *** resultClass ! ***--->
> > <result property="associates" resultClass="BusinessEntity"/>
> > </resultMap>
> >
> > (Is there a work around?)
> >
> > Instead of the above I'm currently having to do:
> >
> > <!-- example poulating the Value Objects -->
> > <resultMap id="beMap2" class="BusinessEntity" groupBy="businessEntityID">
> > <result property="businessEntityID" column="businessEntityID"/>
> > <result property="name" column="name"/>
> >
> > ...// *** having to map all my other props?
> >
> > <result property="addressLine1" column="addressLine1"/>
> > <result property="associates" resultMap="BusinessEntity.assMap2"/>
> > </resultMap>
> >
> > <resultMap id="assMap2"
> class="com.nielsen.ondp.persistence.model.Associate">
> > <result property="firstName" column="firstName"/>
> > <result property="lastName" column="lastName"/>
> >
> > ...// *** having to map all my other props?
> >
> > </resultMap>
> >
> > the simple query:
> >
> > <select id="findBEsWithAssociates2" resultMap="beMap2"
> cacheModel="beCache">
> > SELECT be.*, a.*
> > FROM NPPBusinessEntity be, NPPAssociate a
> > WHERE a.businessEntityID = be.businessEntityID ORDER BY
> be.businessEntityID
> > </select>
> >
>
>
>
> --
> Rick
>
--
Ray McDermott
GSM 047/32.53.854
Re: Am I missing something really simple? Way to avoid adding all props in a map if I decide to add one extra collection to pojo
Posted by Rick <ri...@gmail.com>.
I sent this tot he wrong list before, so I'm resending it. I think it
would be a huge plus for ibatis. I don't mind digging into the source
code... would it be a really tough fix? To modify result maps to allow
them being based on result classes? Has this been brought up before.
Just curious.
To sum up if you don't read the original email - I can easily get this
back in one query and notice how I don't need every property mapped.
(The current way, you need an Address map of every property and and
Associate with every property, when all I want to do is map up the
column names directly to the objects)
<!-- populated all properties on the BusinessEntity class if you can,
without mapping them !!!! --->
<resultMap id="beResult" class="BusinessEntity" groupBy="businessEntityID">
<!-- directly map *** resultClasses not maps ! ***--->
<result property="associates" resultClass="BusinessEntity"/>
<result property="address" resultClass="Address"/>
</resultMap>
for:
BusinessEntity {
String name;
String abbreviation;
Integer id;
//..etc
Address address
List<Associate> associates
}
On Mon, Nov 17, 2008 at 10:56 AM, Rick <ri...@gmail.com> wrote:
> Hopefully I'm just being a newb and missing something simple. It's
> been a while since I worked with iBATIS:)...
>
> My column names and pojo names are the same, so typically I don't even
> need a result map created to map my properties (I can just map my
> resultClass to the query). Where things break down though is if I want
> to nest a collection of another object in one of my pojos. For example
> in the code below BusinessEntity can have "Associates" so I've added a
> List<Associate> field to my BusinessEntity pojo. What I'd love to do
> now is somehow get my BusinessEntity populated and the nested
> Associate lists populated *WITHOUT* having to go through and declare
> EVERY SINGLE property in a Map (since my fields match up fine to the
> columns.) It seems though that I can't do this? Am I missing an easy
> way to avoid this? I wish I could do something like:
>
> <!-- populated all properties on the BusinessEntity class if you can!!!! --->
> <resultMap id="beMap2" class="BusinessEntity" groupBy="businessEntityID">
> <!-- directly map a *** resultClass ! ***--->
> <result property="associates" resultClass="BusinessEntity"/>
> </resultMap>
>
> (Is there a work around?)
>
> Instead of the above I'm currently having to do:
>
> <!-- example poulating the Value Objects -->
> <resultMap id="beMap2" class="BusinessEntity" groupBy="businessEntityID">
> <result property="businessEntityID" column="businessEntityID"/>
> <result property="name" column="name"/>
>
> ...// *** having to map all my other props?
>
> <result property="addressLine1" column="addressLine1"/>
> <result property="associates" resultMap="BusinessEntity.assMap2"/>
> </resultMap>
>
> <resultMap id="assMap2" class="com.nielsen.ondp.persistence.model.Associate">
> <result property="firstName" column="firstName"/>
> <result property="lastName" column="lastName"/>
>
> ...// *** having to map all my other props?
>
> </resultMap>
>
> the simple query:
>
> <select id="findBEsWithAssociates2" resultMap="beMap2" cacheModel="beCache">
> SELECT be.*, a.*
> FROM NPPBusinessEntity be, NPPAssociate a
> WHERE a.businessEntityID = be.businessEntityID ORDER BY be.businessEntityID
> </select>
>
--
Rick