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: Reusing @Results annotation
Date Thu, 10 Sep 2009 18:42:31 GMT
I put a lot of thought into that... I landed on this position:  Java
Annotations suck, and aren't very good at much.  The very little that they
are good for are simple things.  Therefore, I tried to keep the annotations
limited in scope and targeted only simple problems.
If you have advanced needs, I suggest sticking with the XML.

And on a per mapper/namespace level, I suggest using either XML or
annotations, and not both.


On Thu, Sep 10, 2009 at 9:46 AM, Guy Rouillier <guyr-ml1@burntmail.com>wrote:

> I'm new to iBatis, starting out with version 3.  One common usage scenario
> we have is to run different queries that all return the same result type,
> sliced and diced different ways.  Using XML, this is easy to achieve as I
> can have all selects refer to the same ResultMap.  I can't figure out how to
> implement a similar approach using @Results annotation.
> Here is my first example using annotations:
> public interface BundleMapper
>   {
>   @Select(value="select * from bundle where bundle_id = #{id}")
>   @Results(value=
>      {
>       @Result(column="cust_id", property="custId"),
>       @Result(column="status_dt", property="statusDt")
>       })
>   Bundle selectBundle(String id);
>   }
> My Bundle class contains about 30-40 fields, but I just wanted to save some
> typing so I just created two.  This approach seems to require me to define
> @Results for each select.  So if I had another method that also returned
> Bundle, I'd have to define the 40-line @Results annotation again.
> Using annotations, is there any way to define an @Results mapping one time
> and then refer to it multiple times from different methods?
> Also, I think it would be handy to merge XML definitions and annotation
> definitions into a single application-wide namespace, so that I could refer
> to XML definitions from annotations.  That would address the issue I'm
> discussing here.  I could define a ResultMap in XML, then refer to it as
> needed from annotations.
> Thanks.
> --
> Guy Rouillier
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org

View raw message