What happened to remapResults?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

What happened to remapResults?

GregW
I noticed that this is mentioned as a way of creating dynamic select
clauses, yet I can find no mention of it in my 6 June 2011
documentation.  Eclipse does not list it as one of the allowable
attributes for a select tag and when I do put remapResults in there
anyway I get a:

Cause: org.apache.ibatis.builder.BuilderException: Error creating
document instance.  Cause: org.xml.sax.SAXParseException: Attribute
"remapResults" must be declared for element type "select"

Has it disappeared?  Is there a new equivalent to building dynamic
select clauses?  I want to take a List<String> and make this what the
query selects over.  I tried foreach just in case that worked, but
with the $ notation I got spaces instead of commas in between the
individual columns.
Reply | Threaded
Open this post in threaded view
|

Re: What happened to remapResults?

GregH
I did not have that exact case when I asked for help.  My data was actually sql i was pulling from a table and executing against the database.
 
Your need however could be satisfied by running a for loop around the contents and stringing the values in using the query by example criteria.

On Tue, Oct 4, 2011 at 12:09 PM, GregW <[hidden email]> wrote:
I noticed that this is mentioned as a way of creating dynamic select
clauses, yet I can find no mention of it in my 6 June 2011
documentation.  Eclipse does not list it as one of the allowable
attributes for a select tag and when I do put remapResults in there
anyway I get a:

Cause: org.apache.ibatis.builder.BuilderException: Error creating
document instance.  Cause: org.xml.sax.SAXParseException: Attribute
"remapResults" must be declared for element type "select"

Has it disappeared?  Is there a new equivalent to building dynamic
select clauses?  I want to take a List<String> and make this what the
query selects over.  I tried foreach just in case that worked, but
with the $ notation I got spaces instead of commas in between the
individual columns.



--
Greg Hintz
608 395-5123


Reply | Threaded
Open this post in threaded view
|

Re: What happened to remapResults?

Jeff Butler
In reply to this post by GregW
remapResults was used to tell iBATIS that the column list in a query
had changed.  This is no longer necessary with MyBatis as MyBatis does
not cache mappings.

foreach is the correct way to build dynamic queries over a list.
Perhaps if you post your sql map we can help.

Jeff Butler


On Tue, Oct 4, 2011 at 1:09 PM, GregW <[hidden email]> wrote:

> I noticed that this is mentioned as a way of creating dynamic select
> clauses, yet I can find no mention of it in my 6 June 2011
> documentation.  Eclipse does not list it as one of the allowable
> attributes for a select tag and when I do put remapResults in there
> anyway I get a:
>
> Cause: org.apache.ibatis.builder.BuilderException: Error creating
> document instance.  Cause: org.xml.sax.SAXParseException: Attribute
> "remapResults" must be declared for element type "select"
>
> Has it disappeared?  Is there a new equivalent to building dynamic
> select clauses?  I want to take a List<String> and make this what the
> query selects over.  I tried foreach just in case that worked, but
> with the $ notation I got spaces instead of commas in between the
> individual columns.
Reply | Threaded
Open this post in threaded view
|

Re: What happened to remapResults?

GregW
Here is the statement I am trying to do

<select id="getRecord" parameterType="map" resultType="hashmap">
           select
              <foreach item="item" collection="columns">
                 ${item}
               </foreach>
           from ${table}
           where id = #{id}
           and col1 = col2
</select>

In my case, the table I am feeding in right now has over 300 columns
and so select * is not going to work for me even though it would be
the easy way out of this.  So I need (depending upon the table I have
selected) a list of columns in my select statement which is
appropriate for the table I am calling.  This list may end up being
50-60 entries.  In the DB various columns may come and go with time or
possibly be renamed.  As I said, I have a List<String> of column names
to pass in (which I earlier retrieved from a separate table via
MyBatis).  With the above notation, the generated sql is like

select c1 c2 c3 c4 .... c60 from mytable ....

which would work if only commas separated each of the columns.

To be complete, here is my mapper code

   public Map getRecord(@Param("table") String table,
                                   @Param("columns") List<String> columns,
                                   @Param("id") Integer id);





On Oct 4, 7:48 pm, Jeff Butler <[hidden email]> wrote:

> remapResults was used to tell iBATIS that the column list in a query
> had changed.  This is no longer necessary with MyBatis as MyBatis does
> not cache mappings.
>
> foreach is the correct way to build dynamic queries over a list.
> Perhaps if you post your sql map we can help.
>
> Jeff Butler
>
>
>
>
>
>
>
> On Tue, Oct 4, 2011 at 1:09 PM, GregW <[hidden email]> wrote:
> > I noticed that this is mentioned as a way of creating dynamic select
> > clauses, yet I can find no mention of it in my 6 June 2011
> > documentation.  Eclipse does not list it as one of the allowable
> > attributes for a select tag and when I do put remapResults in there
> > anyway I get a:
>
> > Cause: org.apache.ibatis.builder.BuilderException: Error creating
> > document instance.  Cause: org.xml.sax.SAXParseException: Attribute
> > "remapResults" must be declared for element type "select"
>
> > Has it disappeared?  Is there a new equivalent to building dynamic
> > select clauses?  I want to take a List<String> and make this what the
> > query selects over.  I tried foreach just in case that worked, but
> > with the $ notation I got spaces instead of commas in between the
> > individual columns.
Reply | Threaded
Open this post in threaded view
|

Re: What happened to remapResults?

Jeff Butler
You're almost there:

<foreach item="item" collection="columns" separator=",">


Jeff Butler


On 10/5/11, GregW <[hidden email]> wrote:

> Here is the statement I am trying to do
>
> <select id="getRecord" parameterType="map" resultType="hashmap">
>   select
>      <foreach item="item" collection="columns">
>                  ${item}
>       </foreach>
>   from ${table}
>   where id = #{id}
>   and col1 = col2
> </select>
>
> In my case, the table I am feeding in right now has over 300 columns
> and so select * is not going to work for me even though it would be
> the easy way out of this.  So I need (depending upon the table I have
> selected) a list of columns in my select statement which is
> appropriate for the table I am calling.  This list may end up being
> 50-60 entries.  In the DB various columns may come and go with time or
> possibly be renamed.  As I said, I have a List<String> of column names
> to pass in (which I earlier retrieved from a separate table via
> MyBatis).  With the above notation, the generated sql is like
>
> select c1 c2 c3 c4 .... c60 from mytable ....
>
> which would work if only commas separated each of the columns.
>
> To be complete, here is my mapper code
>
>    public Map getRecord(@Param("table") String table,
>                   @Param("columns") List<String> columns,
>                                    @Param("id") Integer id);
>
>
>
>
>
> On Oct 4, 7:48 pm, Jeff Butler <[hidden email]> wrote:
>> remapResults was used to tell iBATIS that the column list in a query
>> had changed.  This is no longer necessary with MyBatis as MyBatis does
>> not cache mappings.
>>
>> foreach is the correct way to build dynamic queries over a list.
>> Perhaps if you post your sql map we can help.
>>
>> Jeff Butler
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Oct 4, 2011 at 1:09 PM, GregW <[hidden email]> wrote:
>> > I noticed that this is mentioned as a way of creating dynamic select
>> > clauses, yet I can find no mention of it in my 6 June 2011
>> > documentation.  Eclipse does not list it as one of the allowable
>> > attributes for a select tag and when I do put remapResults in there
>> > anyway I get a:
>>
>> > Cause: org.apache.ibatis.builder.BuilderException: Error creating
>> > document instance.  Cause: org.xml.sax.SAXParseException: Attribute
>> > "remapResults" must be declared for element type "select"
>>
>> > Has it disappeared?  Is there a new equivalent to building dynamic
>> > select clauses?  I want to take a List<String> and make this what the
>> > query selects over.  I tried foreach just in case that worked, but
>> > with the $ notation I got spaces instead of commas in between the
>> > individual columns.

--
Sent from my mobile device
Reply | Threaded
Open this post in threaded view
|

Re: What happened to remapResults?

GregW
Thanks.  I was used to using the foreach in the where clause where I
don't explicitly mention seperator.  Learned something new.

-Greg

On Oct 5, 11:57 am, Jeff Butler <[hidden email]> wrote:

> You're almost there:
>
> <foreach item="item" collection="columns" separator=",">
>
> Jeff Butler
>
> On 10/5/11, GregW <[hidden email]> wrote:
>
>
>
>
>
>
>
>
>
> > Here is the statement I am trying to do
>
> > <select id="getRecord" parameterType="map" resultType="hashmap">
> >       select
> >          <foreach item="item" collection="columns">
> >                  ${item}
> >           </foreach>
> >       from ${table}
> >       where id = #{id}
> >       and col1 = col2
> > </select>
>
> > In my case, the table I am feeding in right now has over 300 columns
> > and so select * is not going to work for me even though it would be
> > the easy way out of this.  So I need (depending upon the table I have
> > selected) a list of columns in my select statement which is
> > appropriate for the table I am calling.  This list may end up being
> > 50-60 entries.  In the DB various columns may come and go with time or
> > possibly be renamed.  As I said, I have a List<String> of column names
> > to pass in (which I earlier retrieved from a separate table via
> > MyBatis).  With the above notation, the generated sql is like
>
> > select c1 c2 c3 c4 .... c60 from mytable ....
>
> > which would work if only commas separated each of the columns.
>
> > To be complete, here is my mapper code
>
> >    public Map getRecord(@Param("table") String table,
> >                               @Param("columns") List<String> columns,
> >                                    @Param("id") Integer id);
>
> > On Oct 4, 7:48 pm, Jeff Butler <[hidden email]> wrote:
> >> remapResults was used to tell iBATIS that the column list in a query
> >> had changed.  This is no longer necessary with MyBatis as MyBatis does
> >> not cache mappings.
>
> >> foreach is the correct way to build dynamic queries over a list.
> >> Perhaps if you post your sql map we can help.
>
> >> Jeff Butler
>
> >> On Tue, Oct 4, 2011 at 1:09 PM, GregW <[hidden email]> wrote:
> >> > I noticed that this is mentioned as a way of creating dynamic select
> >> > clauses, yet I can find no mention of it in my 6 June 2011
> >> > documentation.  Eclipse does not list it as one of the allowable
> >> > attributes for a select tag and when I do put remapResults in there
> >> > anyway I get a:
>
> >> > Cause: org.apache.ibatis.builder.BuilderException: Error creating
> >> > document instance.  Cause: org.xml.sax.SAXParseException: Attribute
> >> > "remapResults" must be declared for element type "select"
>
> >> > Has it disappeared?  Is there a new equivalent to building dynamic
> >> > select clauses?  I want to take a List<String> and make this what the
> >> > query selects over.  I tried foreach just in case that worked, but
> >> > with the $ notation I got spaces instead of commas in between the
> >> > individual columns.
>
> --
> Sent from my mobile device