ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Mills <developm...@peter.mills.to>
Subject Re: ResultMap with constructor injection
Date Tue, 18 Jul 2006 04:48:07 GMT
Just to recap, in case there's any confusion: constructor injection 
seems to be working perfectly, as long as you're also doing 
property/field injection on the object as well.  Doing constructor 
injection, alone, does not seem to be supported.

I'm not familiar with .xsd schemas, but here is the relevant resultMap 
section of the SqlMap.xsd:

<xs:element name="resultMap">
    <xs:complexType>
    <xs:sequence>
        <xs:element ref="constructor" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="result" maxOccurs="unbounded"/>
        <xs:element ref="discriminator" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="subMap" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" use="required"/>
    <xs:attribute name="class" type="xs:string" use="required"/>
     <xs:attribute name="extends" type="xs:string"/>
     </xs:complexType>
</xs:element>

If the lack of constructor only injection support is only a parsing 
problem, perhaps a minOccurs="0" needs to be added to the "result" element?

Cheers,

Peter
 
Ron Grabowski wrote:

>DataMapper 1.5 supports this notation (IBATISNET-155):
>
><resultMap id="account-result-constructor" class="Account" > 
> <constructor> 
>  <argument argumentName="id" column="Account_ID"/> 
>  <argument argumentName="firstName" column="Account_FirstName"/> 
>  <argument argumentName="lastName" column="Account_LastName"/> 
> </constructor>  
></resultMap>
>
>--- Clinton Begin <clinton.begin@gmail.com> wrote:
>
>  
>
>>In Java land I was thinking of simply adding the following to the
>>current
>><result> element...
>>
>>Currently we can do:
>>
>>    <result property="FirstName" column="FIRST_NAME" />
>>
>>I'd like to add...
>>
>>    <result field="_firstName" column="FIRST_NAME"/>  <!-- I'm not
>>advocating underscores -->
>>
>>...and...
>>
>>    <result column="FIRST_NAME" />
>>
>>The latter (which lacks both property and field attributes) would be
>>a
>>constructor parameter.  It would have to follow some rules:
>>
>>    1) Constructor results must come first in the result map defn.
>>    2) Constructor results must be in the same order as the
>>parameters of
>>the constructor.
>>
>>I think constructor and field support would be awesome in both the
>>.NET and
>>Java versions.
>>
>>Thoughts?
>>
>>Clinton
>>    
>>
>
>  
>


Mime
View raw message