Clinton Begin wrote:
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.
Clinton, thank you very much for the quick reply and for the
suggestions. Fortunately, I've never had to implement annotations
myself, just use them. As you suggest, they don't appear to be up to
the task of defining a ResultMap independent of the method to which it
is attached. That's too bad; would have been nice to be able to move
pieces of the SqlMap between XML and annotations and have them all work
together.
The direction I'm leaning is to standardize on keeping ResultMaps and
the selects that use them in XML, but allow other DML (inserts, updates,
and selects returning a single value like count) to be placed into
annotations.
I like annotations because the SQL is adjacent to the method that uses
it. Our company and software development team are small, so we write
our own SQL. I work within Eclipse; is there any way I can link a
source method to the corresponding SQL definition in the XML mapper
file, such that I can double-click on a method, like my selectBundle
example, and have Eclipse open up the correct XML mapper file with the
cursor on the selectBundle <select> tag?
Thanks.
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.
Cheers,
Clinton
On Thu, Sep 10, 2009 at 9:46 AM, Guy Rouillier <guyr-...@burntmail.com
<mailto:guyr-...@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-unsubscr...@ibatis.apache.org
<mailto:user-java-unsubscr...@ibatis.apache.org>
For additional commands, e-mail: user-java-h...@ibatis.apache.org
<mailto:user-java-h...@ibatis.apache.org>
--
Guy Rouillier
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org