ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Rouillier <guyr-...@burntmail.com>
Subject Re: XML vs Annotations
Date Sat, 06 Feb 2010 06:51:12 GMT
On 2/5/2010 5:15 PM, Daryl Stultz wrote:
> Hello,
> I think it's great that iBatis supports both XML and annotations. I
> don't necessarily prefer one over the other but I kind of prefer to do
> everything one way. The docs state that "You will notice that join
> mapping is not supported via the Annotations API. This is due to the
> limitation in Java Annotations that does not allow for circular
> references." I'm pretty experienced with SQL but It's not clear to me
> exactly what a "join mapping" is. At first I thought it was a
> many-to-many. Can someone give me an example?

Take a look in the documentation in the section titled "Advanced Result 
Mapping".  Basically, annotations allow you to do nested select but not 
nested results.

> If "not everything" can be done with annotations, I'd be inclined to do
> mappings in XML but SQL in Java using SelectBuilder. I seem to be having
> a little trouble wiring things together. I have my <resultMap> in my
> mapper xml file and my Mapper interface specifies the @SelectProvider.
> The query is built and executed properly but the mapper returns a null
> object presumably because the resultMap isn't being found. How do I
> configure my mapper interface and my mapper xml to talk to each other
> (how do I specify the resultMap that goes with the mapper method /
> SelectProvider? I hope that's clear... if not:
> My xml file contains this:
> <resultMap id="userResult" type="User">...
> It used to contain this before experimenting with @SelectProvider:
> <select id="findById" parameterType="Integer" resultMap="userResult">...
> My mapper interface contains this:
> @SelectProvider(type = UserSql.class, method = "findById")
> public User findById(Integer id);
> UserSql.findById is being call just fine. What I expected to have to do
> was specify @ResultMap or @SelectProvider(resultMap = "userResult") to
> connect things.

As you've discovered, iBATIS 3 annotations currently do not provide that 
capability.  If you elect to use annotations, then you'll need to 
provide your result map via annotations also; see @Results.  If you are 
unclear how the @Results annotation works, here is a short sample I used 
when learning this myself:

    @Select(value="select * from bundle where bundle_id = #{id}")
        @Result(column="cust_id", property="custId"),
        @Result(column="status_dt", property="statusDt")

    Bundle selectBundle(String id);

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