Open GoogleCodeExporter opened 9 years ago
I believe that this has already been resolved:
http://code.google.com/p/mybatis/issues/detail?id=15
Original comment by gus4...@gmail.com
on 6 Jan 2012 at 10:51
Jorge, as gus400 pointed (he solved this issue) have a look at the "select"
attribute.
Original comment by eduardo.macarron
on 7 Jan 2012 at 9:49
Hello Eduardo and gus400,
I don't think using the select attribute is addressing the issue, yes, it is
one possible solution as I pointed out in the "Please provide any additional
information below" section of this issue. By saying that one should use the
select attribute in cases like this (immutable objects), isn't it the same as
saying that one cannot use joins (associations/collections) in queries?
Apologies if I've missed something.
Jorge
Original comment by jms.cer...@gmail.com
on 7 Jan 2012 at 11:14
Hi Jorge,
Apologies - I'm not sure if I quite understand what is necessary in this case.
I'll provide a couple of examples that are used in the tests - please let us
know if they provide the functionality that you need:
<resultMap id="blogUsingConstructor" type="Blog">
<constructor>
<idArg column="id" javaType="_int"/>
<arg column="title" javaType="java.lang.String"/>
<arg column="author_id" javaType="domain.blog.Author"
select="org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor"/>
<arg column="id" javaType="java.util.List" select="selectPostsForBlog"/>
</constructor>
</resultMap>
<resultMap id="blogUsingConstructorWithResultMap" type="Blog">
<constructor>
<idArg column="id" javaType="_int"/>
<arg column="title" javaType="java.lang.String"/>
<arg javaType="domain.blog.Author" resultMap="org.apache.ibatis.binding.BoundAuthorMapper.authorResultMap"/>
<arg column="id" javaType="java.util.List" select="selectPostsForBlog"/>
</constructor>
</resultMap>
If this does not provide the functionality that you need please let us know.
Gus.
Original comment by gus4...@gmail.com
on 7 Jan 2012 at 1:22
Hi gus400, thanks for the reply.
Well honestly, I can't say that it doesn't provide the desired end result.
However, it does so at the cost of sending off an extra select which isn't
necessary if I were using setter initialization.
** With setter initialization:
select
b.id as blog_id,
b.title as blog_title,
p.id as post_id,
p.comment as post_comment
from blog b
inner join post p on b.id = p.blog_id
where b.id=100;
where the "collection" attribute will support the posts returned:
...
<collection property="posts" ofType="Post" resultMap="postResultMap"/>
...
** With constructor initialization I essentially have to do it two steps:
select
b.id as blog_id,
b.title as blog_title
from blog b
where b.id=100;
select
p.id as post_id,
p.comment as post_comment
from post
where p.blog_id=100;
In the testing and design phase I started off with mutable domain objects. When
I started the implementation phase and changed to immutable objects I realized
I needed to also change most of my queries. It felt like I was being punished
for wanting to use immutable objects :-)
Also, using constructor initialization means that I cannot perform one-to-many
joins.
Thanks again,
Jorge.
Original comment by jms.cer...@gmail.com
on 7 Jan 2012 at 10:06
Sorry, it took me a while to understand what you wanted, but I get it now! :)
I'll take a look into it and see if I can create a patch.
Eduardo/whoever - I think this needs to be a separate bug rather than merged
into issue 15.
Gus
Original comment by gus4...@gmail.com
on 8 Jan 2012 at 10:22
Hi gus400,
If you require more info let me know.
Thanks,
Jorge
Original comment by jms.cer...@gmail.com
on 9 Jan 2012 at 10:02
[deleted comment]
[deleted comment]
[deleted comment]
I have added a failing test for this issue in r4668. But... I have no idea
about how to fix it. :)
Original comment by eduardo.macarron
on 6 Feb 2012 at 12:12
[deleted comment]
[deleted comment]
I'm running into the same issue as Jorge. We too were interested in having
mybatis return immutable pojos and we'd prefer to use multiple joins to build
out collections and associations as nested ResultMaps as opposed to having to
make additional select calls which increases database twitter. Is there a way
to reopen this issue?
Original comment by Daniel.L...@gmail.com
on 21 Mar 2013 at 11:13
This issue follows at
https://github.com/mybatis/mybatis-3/issues/101
Original comment by eduardo.macarron
on 22 Nov 2013 at 8:18
Original issue reported on code.google.com by
jms.cer...@gmail.com
on 24 Dec 2011 at 11:42