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 "Ing. Jan Novotný" <no...@gmail.com> on 2010/02/18 12:47:13 UTC
Ussage pattern for @Many and @One
Hello,
after several minutes of trying I make up how to use @Many annotation -
there is no example of it neither in documentation nor in iBatis test suite:
@Select(
"select product.*, product.id as idProduct, productGroup.name as
groupName, productGroup.groupType" +
" from product inner join productGroup on idGroup =
productGroup.id" +
" where id = #{id}"
)
@Results({
@Result(property = "id", id = true),
@Result(property = "name"),
@Result(property = "group.id", column = "idGroup", id = true),
@Result(property = "group.name", column = "groupName"),
@Result(property = "group.groupType", column = "groupType"),
@Result(property = "tags", column = "idProduct",
many = @Many(select =
"cz.novoj.ibatis.ProductMapper.getTagsForProduct")
)
})
Product getFullProductByIdAnnotation(int id);
@Select("select tag.id, tag.name" +
" from tag inner join productTag on productTag.idTag = tag.id"
+
" where productTag.idProduct = #{value}"
)
List<Tag> getTagsForProduct(int idProduct);
I deduce, that I am not able to define collection loading in annotations
other way than by lazy select (N + 1 problem?!). I don't see how to use it
for single joined SQLs. Am I right?
Cheers Jan
--
--------------------------------------------------------------
Ing. Jan Novotný
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
http://blog.novoj.net
Myšlenky dne otce Fura
--------------------------------------------------------------
Re: Ussage pattern for @Many and @One
Posted by "Ing. Jan Novotný" <no...@gmail.com>.
I will try to do it. I might also contribute my presentation with example
test cases - if you are interested.
Jan
2010/2/18 Clinton Begin <cl...@gmail.com>
> Answered in a previous email RE: limitations of annotations.
>
> As for the documentation, please contribute an example that you find
> helpful to the Wiki mentioned in the first couple of pages of the docs.
>
> Clinton
>
> 2010/2/18 Ing. Jan Novotný <no...@gmail.com>
>
>> Hello,
>>
>>
>> after several minutes of trying I make up how to use @Many annotation -
>> there is no example of it neither in documentation nor in iBatis test suite:
>>
>> @Select(
>> "select product.*, product.id as idProduct, productGroup.name
>> as groupName, productGroup.groupType" +
>> " from product inner join productGroup on idGroup =
>> productGroup.id" +
>> " where id = #{id}"
>> )
>> @Results({
>> @Result(property = "id", id = true),
>> @Result(property = "name"),
>> @Result(property = "group.id", column = "idGroup", id = true),
>> @Result(property = "group.name", column = "groupName"),
>> @Result(property = "group.groupType", column = "groupType"),
>> @Result(property = "tags", column = "idProduct",
>> many = @Many(select =
>> "cz.novoj.ibatis.ProductMapper.getTagsForProduct")
>> )
>> })
>> Product getFullProductByIdAnnotation(int id);
>>
>> @Select("select tag.id, tag.name" +
>> " from tag inner join productTag on productTag.idTag =
>> tag.id" +
>> " where productTag.idProduct = #{value}"
>> )
>> List<Tag> getTagsForProduct(int idProduct);
>>
>> I deduce, that I am not able to define collection loading in
>> annotations other way than by lazy select (N + 1 problem?!). I don't see how
>> to use it for single joined SQLs. Am I right?
>>
>> Cheers Jan
>>
>> --
>> --------------------------------------------------------------
>> Ing. Jan Novotný
>> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>> http://blog.novoj.net
>> Myšlenky dne otce Fura
>> --------------------------------------------------------------
>>
>
>
--
--------------------------------------------------------------
Ing. Jan Novotný
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
http://blog.novoj.net
Myšlenky dne otce Fura
--------------------------------------------------------------
Re: Ussage pattern for @Many and @One
Posted by Clinton Begin <cl...@gmail.com>.
Answered in a previous email RE: limitations of annotations.
As for the documentation, please contribute an example that you find helpful
to the Wiki mentioned in the first couple of pages of the docs.
Clinton
2010/2/18 Ing. Jan Novotný <no...@gmail.com>
> Hello,
>
> after several minutes of trying I make up how to use @Many annotation -
> there is no example of it neither in documentation nor in iBatis test suite:
>
> @Select(
> "select product.*, product.id as idProduct, productGroup.name
> as groupName, productGroup.groupType" +
> " from product inner join productGroup on idGroup =
> productGroup.id" +
> " where id = #{id}"
> )
> @Results({
> @Result(property = "id", id = true),
> @Result(property = "name"),
> @Result(property = "group.id", column = "idGroup", id = true),
> @Result(property = "group.name", column = "groupName"),
> @Result(property = "group.groupType", column = "groupType"),
> @Result(property = "tags", column = "idProduct",
> many = @Many(select =
> "cz.novoj.ibatis.ProductMapper.getTagsForProduct")
> )
> })
> Product getFullProductByIdAnnotation(int id);
>
> @Select("select tag.id, tag.name" +
> " from tag inner join productTag on productTag.idTag = tag.id"
> +
> " where productTag.idProduct = #{value}"
> )
> List<Tag> getTagsForProduct(int idProduct);
>
> I deduce, that I am not able to define collection loading in annotations
> other way than by lazy select (N + 1 problem?!). I don't see how to use it
> for single joined SQLs. Am I right?
>
> Cheers Jan
>
> --
> --------------------------------------------------------------
> Ing. Jan Novotný
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> http://blog.novoj.net
> Myšlenky dne otce Fura
> --------------------------------------------------------------
>