ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: Ussage pattern for @Many and @One
Date Thu, 18 Feb 2010 16:01:53 GMT
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ý <novotnaci@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
> --------------------------------------------------------------
>

Mime
View raw message