You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Landry Soules <la...@gmail.com> on 2006/11/05 19:16:03 UTC
redundancy in resultmap declaration ?
Hello,
Regarding complex properties, is there a way to declare only once the
corresponding resultmap ?
Example : an Address class and a Country class.
In country_SqlMap.xml i have :
<sqlMap namespace="country" >
<resultMap id="result-country" class="com.seenxl.model.Country" >
<result column="id" property="id" jdbcType="CHAR" />
<result column="iso3" property="iso3" jdbcType="CHAR" />
<result column="name" property="name" jdbcType="CHAR" />
<result column="num_code" property="numCode" jdbcType="SMALLINT" />
<result column="printable_name" property="printableName"
jdbcType="CHAR" />
</resultMap>
...
In address_SqlMap.xml :
<sqlMap namespace="address" >
<resultMap id="result-address" class="com.seenxl.model.Address" >
<result column="id" property="id" jdbcType="INTEGER" />
<result column="add1" property="add1" jdbcType="VARCHAR" />
<result column="add2" property="add2" jdbcType="VARCHAR" />
<result column="city" property="city" jdbcType="VARCHAR" />
<result column="zip_code" property="zipCode" jdbcType="VARCHAR" />
<result column="country" property="country"
select="address.getCountry" />
<result column="state" property="state" jdbcType="INTEGER" />
</resultMap>
In order to map getCountry with its result, i would like to refer to the
result map defined in country_SqlMap.xml, like this :
<select id="getCountry" parameterClass="string"
resultMap="country.result-country">
select * from country where id = #value#
</select>
But i get an error :
...
Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
Cause: java.lang.RuntimeException: Error parsing XPath
'/sqlMap/select'. Cause: com.ibatis.sqlmap.client.SqlMapException:
There is no result map named country.result-country in this SqlMap.
at com.seenxl.persistence.DaoConfig.<clinit>(DaoConfig.java:40)
... 14 more
So i have to copy country.result-country in address_SqlMap.xml...
What is the way to use a resultMap outside of its sqlmap ?
Re: redundancy in resultmap declaration ?
Posted by Landry Soules <la...@gmail.com>.
Wow, i've been really dumb !
Excuse me, i didn't realize at first that you talked about
sql-map-config.xml.
It works now.
Thanks a lot.
Landry
Larry Meadors a écrit :
> Well, you just have to make sure that before you refer to a result map
> that it is defined.
>
> For example, if you have two result maps "rmCity" and "rmState", and
> "rmState" uses "rmCity" to build a list of cities per state, then you
> have to define "rmCity" first. If you define them in two files - like
> City.xml and State.xml, then you have to include City.xml in your
> sql-map-config file *before* you include State.xml.
>
> Does that help?
>
> Larry
>
>
> On 11/7/06, Landry Soules <la...@gmail.com> wrote:
>> Thank you for the answer Larry, but can you please be more explicit, as
>> i don't know how to achieve this....
>>
>> Where to include country.resultmap in my code ?
>>
>> <sqlMap namespace="address" >
>>
>>
>> <resultMap id="result-address" class="com.seenxl.model.Address" >
>> <result column="id" property="id" jdbcType="INTEGER" />
>> <result column="add1" property="add1" jdbcType="VARCHAR" />
>> <result column="add2" property="add2" jdbcType="VARCHAR" />
>> <result column="city" property="city" jdbcType="VARCHAR" />
>> <result column="zip_code" property="zipCode" jdbcType="VARCHAR" />
>> <result column="country" property="country"
>> select="address.getCountry" />
>> <result column="state" property="state" jdbcType="INTEGER" />
>> </resultMap>
>> ......
>>
>> <select id="getCountry" parameterClass="string"
>> resultMap="country.result-country">
>> select * from country where id = #value#
>> </select>
>> ....
>>
>> </sqlMap>
>>
>>
>> Larry Meadors a écrit :
>> > Include the result maps before including the mapped statements.
>> >
>> > This is sort of a minibug that we haven't gotten around to fixing,
>> > because it hasn't been to hard to work around. ;-)
>> >
>> > Larry
>> >
>> >
>> > On 11/5/06, Landry Soules <la...@gmail.com> wrote:
>> >> Hello,
>> >>
>> >> Regarding complex properties, is there a way to declare only once the
>> >> corresponding resultmap ?
>> >>
>> >> Example : an Address class and a Country class.
>> >>
>> >>
>> >> In country_SqlMap.xml i have :
>> >>
>> >> <sqlMap namespace="country" >
>> >> <resultMap id="result-country" class="com.seenxl.model.Country" >
>> >>
>> >> <result column="id" property="id" jdbcType="CHAR" />
>> >> <result column="iso3" property="iso3" jdbcType="CHAR" />
>> >> <result column="name" property="name" jdbcType="CHAR" />
>> >> <result column="num_code" property="numCode"
>> jdbcType="SMALLINT" />
>> >> <result column="printable_name" property="printableName"
>> >> jdbcType="CHAR" />
>> >> </resultMap>
>> >> ...
>> >>
>> >> In address_SqlMap.xml :
>> >>
>> >> <sqlMap namespace="address" >
>> >>
>> >>
>> >> <resultMap id="result-address" class="com.seenxl.model.Address" >
>> >> <result column="id" property="id" jdbcType="INTEGER" />
>> >> <result column="add1" property="add1" jdbcType="VARCHAR" />
>> >> <result column="add2" property="add2" jdbcType="VARCHAR" />
>> >> <result column="city" property="city" jdbcType="VARCHAR" />
>> >> <result column="zip_code" property="zipCode"
>> jdbcType="VARCHAR" />
>> >> <result column="country" property="country"
>> >> select="address.getCountry" />
>> >> <result column="state" property="state" jdbcType="INTEGER" />
>> >> </resultMap>
>> >>
>> >> In order to map getCountry with its result, i would like to refer
>> to the
>> >> result map defined in country_SqlMap.xml, like this :
>> >>
>> >> <select id="getCountry" parameterClass="string"
>> >> resultMap="country.result-country">
>> >> select * from country where id = #value#
>> >> </select>
>> >>
>> >> But i get an error :
>> >>
>> >> ...
>> >> Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
>> >> Cause: java.lang.RuntimeException: Error parsing XPath
>> >> '/sqlMap/select'. Cause: com.ibatis.sqlmap.client.SqlMapException:
>> >> There is no result map named country.result-country in this SqlMap.
>> >> at com.seenxl.persistence.DaoConfig.<clinit>(DaoConfig.java:40)
>> >> ... 14 more
>> >>
>> >> So i have to copy country.result-country in address_SqlMap.xml...
>> >>
>> >> What is the way to use a resultMap outside of its sqlmap ?
>> >>
>> >
>>
>>
>
Re: redundancy in resultmap declaration ?
Posted by Larry Meadors <lm...@apache.org>.
Well, you just have to make sure that before you refer to a result map
that it is defined.
For example, if you have two result maps "rmCity" and "rmState", and
"rmState" uses "rmCity" to build a list of cities per state, then you
have to define "rmCity" first. If you define them in two files - like
City.xml and State.xml, then you have to include City.xml in your
sql-map-config file *before* you include State.xml.
Does that help?
Larry
On 11/7/06, Landry Soules <la...@gmail.com> wrote:
> Thank you for the answer Larry, but can you please be more explicit, as
> i don't know how to achieve this....
>
> Where to include country.resultmap in my code ?
>
> <sqlMap namespace="address" >
>
>
> <resultMap id="result-address" class="com.seenxl.model.Address" >
> <result column="id" property="id" jdbcType="INTEGER" />
> <result column="add1" property="add1" jdbcType="VARCHAR" />
> <result column="add2" property="add2" jdbcType="VARCHAR" />
> <result column="city" property="city" jdbcType="VARCHAR" />
> <result column="zip_code" property="zipCode" jdbcType="VARCHAR" />
> <result column="country" property="country"
> select="address.getCountry" />
> <result column="state" property="state" jdbcType="INTEGER" />
> </resultMap>
> ......
>
> <select id="getCountry" parameterClass="string"
> resultMap="country.result-country">
> select * from country where id = #value#
> </select>
> ....
>
> </sqlMap>
>
>
> Larry Meadors a écrit :
> > Include the result maps before including the mapped statements.
> >
> > This is sort of a minibug that we haven't gotten around to fixing,
> > because it hasn't been to hard to work around. ;-)
> >
> > Larry
> >
> >
> > On 11/5/06, Landry Soules <la...@gmail.com> wrote:
> >> Hello,
> >>
> >> Regarding complex properties, is there a way to declare only once the
> >> corresponding resultmap ?
> >>
> >> Example : an Address class and a Country class.
> >>
> >>
> >> In country_SqlMap.xml i have :
> >>
> >> <sqlMap namespace="country" >
> >> <resultMap id="result-country" class="com.seenxl.model.Country" >
> >>
> >> <result column="id" property="id" jdbcType="CHAR" />
> >> <result column="iso3" property="iso3" jdbcType="CHAR" />
> >> <result column="name" property="name" jdbcType="CHAR" />
> >> <result column="num_code" property="numCode" jdbcType="SMALLINT" />
> >> <result column="printable_name" property="printableName"
> >> jdbcType="CHAR" />
> >> </resultMap>
> >> ...
> >>
> >> In address_SqlMap.xml :
> >>
> >> <sqlMap namespace="address" >
> >>
> >>
> >> <resultMap id="result-address" class="com.seenxl.model.Address" >
> >> <result column="id" property="id" jdbcType="INTEGER" />
> >> <result column="add1" property="add1" jdbcType="VARCHAR" />
> >> <result column="add2" property="add2" jdbcType="VARCHAR" />
> >> <result column="city" property="city" jdbcType="VARCHAR" />
> >> <result column="zip_code" property="zipCode" jdbcType="VARCHAR" />
> >> <result column="country" property="country"
> >> select="address.getCountry" />
> >> <result column="state" property="state" jdbcType="INTEGER" />
> >> </resultMap>
> >>
> >> In order to map getCountry with its result, i would like to refer to the
> >> result map defined in country_SqlMap.xml, like this :
> >>
> >> <select id="getCountry" parameterClass="string"
> >> resultMap="country.result-country">
> >> select * from country where id = #value#
> >> </select>
> >>
> >> But i get an error :
> >>
> >> ...
> >> Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
> >> Cause: java.lang.RuntimeException: Error parsing XPath
> >> '/sqlMap/select'. Cause: com.ibatis.sqlmap.client.SqlMapException:
> >> There is no result map named country.result-country in this SqlMap.
> >> at com.seenxl.persistence.DaoConfig.<clinit>(DaoConfig.java:40)
> >> ... 14 more
> >>
> >> So i have to copy country.result-country in address_SqlMap.xml...
> >>
> >> What is the way to use a resultMap outside of its sqlmap ?
> >>
> >
>
>
Re: redundancy in resultmap declaration ?
Posted by Landry Soules <la...@gmail.com>.
Thank you for the answer Larry, but can you please be more explicit, as
i don't know how to achieve this....
Where to include country.resultmap in my code ?
<sqlMap namespace="address" >
<resultMap id="result-address" class="com.seenxl.model.Address" >
<result column="id" property="id" jdbcType="INTEGER" />
<result column="add1" property="add1" jdbcType="VARCHAR" />
<result column="add2" property="add2" jdbcType="VARCHAR" />
<result column="city" property="city" jdbcType="VARCHAR" />
<result column="zip_code" property="zipCode" jdbcType="VARCHAR" />
<result column="country" property="country"
select="address.getCountry" />
<result column="state" property="state" jdbcType="INTEGER" />
</resultMap>
......
<select id="getCountry" parameterClass="string"
resultMap="country.result-country">
select * from country where id = #value#
</select>
....
</sqlMap>
Larry Meadors a écrit :
> Include the result maps before including the mapped statements.
>
> This is sort of a minibug that we haven't gotten around to fixing,
> because it hasn't been to hard to work around. ;-)
>
> Larry
>
>
> On 11/5/06, Landry Soules <la...@gmail.com> wrote:
>> Hello,
>>
>> Regarding complex properties, is there a way to declare only once the
>> corresponding resultmap ?
>>
>> Example : an Address class and a Country class.
>>
>>
>> In country_SqlMap.xml i have :
>>
>> <sqlMap namespace="country" >
>> <resultMap id="result-country" class="com.seenxl.model.Country" >
>>
>> <result column="id" property="id" jdbcType="CHAR" />
>> <result column="iso3" property="iso3" jdbcType="CHAR" />
>> <result column="name" property="name" jdbcType="CHAR" />
>> <result column="num_code" property="numCode" jdbcType="SMALLINT" />
>> <result column="printable_name" property="printableName"
>> jdbcType="CHAR" />
>> </resultMap>
>> ...
>>
>> In address_SqlMap.xml :
>>
>> <sqlMap namespace="address" >
>>
>>
>> <resultMap id="result-address" class="com.seenxl.model.Address" >
>> <result column="id" property="id" jdbcType="INTEGER" />
>> <result column="add1" property="add1" jdbcType="VARCHAR" />
>> <result column="add2" property="add2" jdbcType="VARCHAR" />
>> <result column="city" property="city" jdbcType="VARCHAR" />
>> <result column="zip_code" property="zipCode" jdbcType="VARCHAR" />
>> <result column="country" property="country"
>> select="address.getCountry" />
>> <result column="state" property="state" jdbcType="INTEGER" />
>> </resultMap>
>>
>> In order to map getCountry with its result, i would like to refer to the
>> result map defined in country_SqlMap.xml, like this :
>>
>> <select id="getCountry" parameterClass="string"
>> resultMap="country.result-country">
>> select * from country where id = #value#
>> </select>
>>
>> But i get an error :
>>
>> ...
>> Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
>> Cause: java.lang.RuntimeException: Error parsing XPath
>> '/sqlMap/select'. Cause: com.ibatis.sqlmap.client.SqlMapException:
>> There is no result map named country.result-country in this SqlMap.
>> at com.seenxl.persistence.DaoConfig.<clinit>(DaoConfig.java:40)
>> ... 14 more
>>
>> So i have to copy country.result-country in address_SqlMap.xml...
>>
>> What is the way to use a resultMap outside of its sqlmap ?
>>
>
Re: redundancy in resultmap declaration ?
Posted by Larry Meadors <lm...@apache.org>.
Include the result maps before including the mapped statements.
This is sort of a minibug that we haven't gotten around to fixing,
because it hasn't been to hard to work around. ;-)
Larry
On 11/5/06, Landry Soules <la...@gmail.com> wrote:
> Hello,
>
> Regarding complex properties, is there a way to declare only once the
> corresponding resultmap ?
>
> Example : an Address class and a Country class.
>
>
> In country_SqlMap.xml i have :
>
> <sqlMap namespace="country" >
> <resultMap id="result-country" class="com.seenxl.model.Country" >
>
> <result column="id" property="id" jdbcType="CHAR" />
> <result column="iso3" property="iso3" jdbcType="CHAR" />
> <result column="name" property="name" jdbcType="CHAR" />
> <result column="num_code" property="numCode" jdbcType="SMALLINT" />
> <result column="printable_name" property="printableName"
> jdbcType="CHAR" />
> </resultMap>
> ...
>
> In address_SqlMap.xml :
>
> <sqlMap namespace="address" >
>
>
> <resultMap id="result-address" class="com.seenxl.model.Address" >
> <result column="id" property="id" jdbcType="INTEGER" />
> <result column="add1" property="add1" jdbcType="VARCHAR" />
> <result column="add2" property="add2" jdbcType="VARCHAR" />
> <result column="city" property="city" jdbcType="VARCHAR" />
> <result column="zip_code" property="zipCode" jdbcType="VARCHAR" />
> <result column="country" property="country"
> select="address.getCountry" />
> <result column="state" property="state" jdbcType="INTEGER" />
> </resultMap>
>
> In order to map getCountry with its result, i would like to refer to the
> result map defined in country_SqlMap.xml, like this :
>
> <select id="getCountry" parameterClass="string"
> resultMap="country.result-country">
> select * from country where id = #value#
> </select>
>
> But i get an error :
>
> ...
> Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
> Cause: java.lang.RuntimeException: Error parsing XPath
> '/sqlMap/select'. Cause: com.ibatis.sqlmap.client.SqlMapException:
> There is no result map named country.result-country in this SqlMap.
> at com.seenxl.persistence.DaoConfig.<clinit>(DaoConfig.java:40)
> ... 14 more
>
> So i have to copy country.result-country in address_SqlMap.xml...
>
> What is the way to use a resultMap outside of its sqlmap ?
>