Discussion:
iBatis 3.x common sql fragments?
Alex Sherwin
2010-02-08 14:40:36 UTC
Permalink
I'm trying to create a "common" Sql Map XML file that will contain some
common fragments. In iBatis 2.x this was easy enough, the fragments
were referenced by other Sql Map files by using <include
refid="fully.qualified.ns.Statement"/>

I assumed the same would be true for iBatis 3.x as well, but doesn't
seem to be working for me. Right now, the only mapper I have in my
config xml in the <mappers> element is my common xml fragment, while the
rest of my mappers are registered with iBatis programatically. I gave
my common Sql Map a namespace of "common", and tried to reference a
statement from another SqlMap with <sql refid="common.params"/>, I see
this exception:

java.lang.RuntimeException: Error parsing Mapper XML. Cause:
org.apache.ibatis.builder.BuilderException: Could not find SQL statement
to include with refid 'common.params'

Now, in iBatis 2.x I know all of the statements were validated when the
configuration was loaded, so any commonly used fragments had to be
registered first. This might be my problem here, however, I don't know
how to check if that's true since my regular mappers are loaded
programatically and the common is configured in the configuration XML
Martin Ellis
2010-02-08 15:01:13 UTC
Permalink
Post by Alex Sherwin
I'm trying to create a "common" Sql Map XML file that will contain some
common fragments.  In iBatis 2.x this was easy enough, the fragments were
referenced by other Sql Map files by using <include
refid="fully.qualified.ns.Statement"/>
I assumed the same would be true for iBatis 3.x as well, but doesn't seem to
be working for me. Right now, the only mapper I have in my config xml in the
<mappers> element is my common xml fragment, while the rest of my mappers
are registered with iBatis programatically.  I gave my common Sql Map a
namespace of "common", and tried to reference a statement from another
I'm using something like this, which works fine:

<select id="series" parameterType="map" resultMap="...">
SELECT ...
<where>
<include refid="seriesFilter"/>
</where>
</select>

<sql id="seriesFilter">
...

N.B. The tag I'm using is 'include', and I didn't need to qualify the sql id.

Martin
Alex Sherwin
2010-02-08 15:05:40 UTC
Permalink
Post by Martin Ellis
Post by Alex Sherwin
I'm trying to create a "common" Sql Map XML file that will contain some
common fragments. In iBatis 2.x this was easy enough, the fragments were
referenced by other Sql Map files by using <include
refid="fully.qualified.ns.Statement"/>
I assumed the same would be true for iBatis 3.x as well, but doesn't seem to
be working for me. Right now, the only mapper I have in my config xml in the
<mappers> element is my common xml fragment, while the rest of my mappers
are registered with iBatis programatically. I gave my common Sql Map a
namespace of "common", and tried to reference a statement from another
<select id="series" parameterType="map" resultMap="...">
SELECT ...
<where>
<include refid="seriesFilter"/>
</where>
</select>
<sql id="seriesFilter">
...
N.B. The tag I'm using is 'include', and I didn't need to qualify the sql id.
Martin
---------------------------------------------------------------------
That does work, within the same XML document; I'm trying to reference a
<sql> fragment that is defined in a different XML document
Jeff Butler
2010-02-08 15:23:03 UTC
Permalink
I'm doing this (across different xml files). I believe ibatis is still
load order dependant - so your fragments file needs to be loaded in
the configuration before the file that uses the fragments.

Jeff Butler
Post by Alex Sherwin
Post by Martin Ellis
Post by Alex Sherwin
I'm trying to create a "common" Sql Map XML file that will contain some
common fragments. In iBatis 2.x this was easy enough, the fragments were
referenced by other Sql Map files by using <include
refid="fully.qualified.ns.Statement"/>
I assumed the same would be true for iBatis 3.x as well, but doesn't seem to
be working for me. Right now, the only mapper I have in my config xml in the
<mappers> element is my common xml fragment, while the rest of my mappers
are registered with iBatis programatically. I gave my common Sql Map a
namespace of "common", and tried to reference a statement from another
<select id="series" parameterType="map" resultMap="...">
SELECT ...
<where>
<include refid="seriesFilter"/>
</where>
</select>
<sql id="seriesFilter">
...
N.B. The tag I'm using is 'include', and I didn't need to qualify the sql id.
Martin
---------------------------------------------------------------------
That does work, within the same XML document; I'm trying to reference a
<sql> fragment that is defined in a different XML document
---------------------------------------------------------------------
--
Sent from my mobile device
Alex Sherwin
2010-02-08 15:50:16 UTC
Permalink
Are you registering your mappers all in the configuration XML? I tried
to programatically register my common SqlMap file first, and I'm still
having the same problem. I'm wondering if that is my problem
Post by Jeff Butler
I'm doing this (across different xml files). I believe ibatis is still
load order dependant - so your fragments file needs to be loaded in
the configuration before the file that uses the fragments.
Jeff Butler
Post by Alex Sherwin
Post by Martin Ellis
Post by Alex Sherwin
I'm trying to create a "common" Sql Map XML file that will contain some
common fragments. In iBatis 2.x this was easy enough, the fragments were
referenced by other Sql Map files by using <include
refid="fully.qualified.ns.Statement"/>
I assumed the same would be true for iBatis 3.x as well, but doesn't seem to
be working for me. Right now, the only mapper I have in my config xml in the
<mappers> element is my common xml fragment, while the rest of my mappers
are registered with iBatis programatically. I gave my common Sql Map a
namespace of "common", and tried to reference a statement from another
<select id="series" parameterType="map" resultMap="...">
SELECT ...
<where>
<include refid="seriesFilter"/>
</where>
</select>
<sql id="seriesFilter">
...
N.B. The tag I'm using is 'include', and I didn't need to qualify the sql id.
Martin
---------------------------------------------------------------------
That does work, within the same XML document; I'm trying to reference a
<sql> fragment that is defined in a different XML document
---------------------------------------------------------------------
Jeff Butler
2010-02-08 15:53:40 UTC
Permalink
Yes - everything's in xml for me.

Jeff Butler
Post by Alex Sherwin
Are you registering your mappers all in the configuration XML? I tried
to programatically register my common SqlMap file first, and I'm still
having the same problem. I'm wondering if that is my problem
Post by Jeff Butler
I'm doing this (across different xml files). I believe ibatis is still
load order dependant - so your fragments file needs to be loaded in
the configuration before the file that uses the fragments.
Jeff Butler
Post by Alex Sherwin
Post by Martin Ellis
Post by Alex Sherwin
I'm trying to create a "common" Sql Map XML file that will contain some
common fragments. In iBatis 2.x this was easy enough, the fragments were
referenced by other Sql Map files by using <include
refid="fully.qualified.ns.Statement"/>
I assumed the same would be true for iBatis 3.x as well, but doesn't
seem
to
be working for me. Right now, the only mapper I have in my config xml
in
the
<mappers> element is my common xml fragment, while the rest of my mappers
are registered with iBatis programatically. I gave my common Sql Map a
namespace of "common", and tried to reference a statement from another
<select id="series" parameterType="map" resultMap="...">
SELECT ...
<where>
<include refid="seriesFilter"/>
</where>
</select>
<sql id="seriesFilter">
...
N.B. The tag I'm using is 'include', and I didn't need to qualify the
sql
id.
Martin
---------------------------------------------------------------------
That does work, within the same XML document; I'm trying to reference a
<sql> fragment that is defined in a different XML document
---------------------------------------------------------------------
---------------------------------------------------------------------
--
Sent from my mobile device
Clinton Begin
2010-02-08 16:53:06 UTC
Permalink
SQL fragments are order dependent, as they sort of act like an "include".
Most everything should be independent of order now, but there are a few
exceptions.

Clinton
Post by Jeff Butler
Yes - everything's in xml for me.
Jeff Butler
Post by Alex Sherwin
Are you registering your mappers all in the configuration XML? I tried
to programatically register my common SqlMap file first, and I'm still
having the same problem. I'm wondering if that is my problem
Post by Jeff Butler
I'm doing this (across different xml files). I believe ibatis is still
load order dependant - so your fragments file needs to be loaded in
the configuration before the file that uses the fragments.
Jeff Butler
Post by Alex Sherwin
Post by Martin Ellis
Post by Alex Sherwin
I'm trying to create a "common" Sql Map XML file that will contain
some
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
Post by Martin Ellis
Post by Alex Sherwin
common fragments. In iBatis 2.x this was easy enough, the fragments were
referenced by other Sql Map files by using <include
refid="fully.qualified.ns.Statement"/>
I assumed the same would be true for iBatis 3.x as well, but doesn't
seem
to
be working for me. Right now, the only mapper I have in my config xml
in
the
<mappers> element is my common xml fragment, while the rest of my mappers
are registered with iBatis programatically. I gave my common Sql Map
a
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
Post by Martin Ellis
Post by Alex Sherwin
namespace of "common", and tried to reference a statement from
another
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
Post by Martin Ellis
<select id="series" parameterType="map" resultMap="...">
SELECT ...
<where>
<include refid="seriesFilter"/>
</where>
</select>
<sql id="seriesFilter">
...
N.B. The tag I'm using is 'include', and I didn't need to qualify the
sql
id.
Martin
---------------------------------------------------------------------
That does work, within the same XML document; I'm trying to reference a
<sql> fragment that is defined in a different XML document
---------------------------------------------------------------------
---------------------------------------------------------------------
--
Sent from my mobile device
---------------------------------------------------------------------
Alex Sherwin
2010-02-08 17:42:40 UTC
Permalink
Hi Clinton,

I've got a Mapper interface "com.something.CommonMapper.java" and
associated XML SqlMap file "com/something/CommonMapper.xml".

If I register this first, programatically, with
Configuration.addMapper(CommonMapper.java) before any of my other
mappers, I still the an error where <include
refid="com.something.CommonMapper.someStatement"/> cannot be resolved.
The same is also true if I register CommonMapper through the
configuration XML instead.

All of my other mappers, which are attempting to utilize statements
within CommonMapper are registered programatically (after CommonMapper)

I'm using ibatis-3-core-3.0.0.227
Post by Clinton Begin
SQL fragments are order dependent, as they sort of act like an
"include". Most everything should be independent of order now, but
there are a few exceptions.
Clinton
Yes - everything's in xml for me.
Jeff Butler
Post by Alex Sherwin
Are you registering your mappers all in the configuration XML?
I tried
Post by Alex Sherwin
to programatically register my common SqlMap file first, and I'm
still
Post by Alex Sherwin
having the same problem. I'm wondering if that is my problem
Post by Jeff Butler
I'm doing this (across different xml files). I believe ibatis
is still
Post by Alex Sherwin
Post by Jeff Butler
load order dependant - so your fragments file needs to be loaded in
the configuration before the file that uses the fragments.
Jeff Butler
Post by Alex Sherwin
On 8 February 2010 14:40, Alex Sherwin
Post by Alex Sherwin
I'm trying to create a "common" Sql Map XML file that will
contain some
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
Post by Alex Sherwin
common fragments. In iBatis 2.x this was easy enough, the
fragments
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
Post by Alex Sherwin
were
referenced by other Sql Map files by using <include
refid="fully.qualified.ns.Statement"/>
I assumed the same would be true for iBatis 3.x as well, but
doesn't
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
Post by Alex Sherwin
seem
to
be working for me. Right now, the only mapper I have in my
config xml
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
Post by Alex Sherwin
in
the
<mappers> element is my common xml fragment, while the rest
of my
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
Post by Alex Sherwin
mappers
are registered with iBatis programatically. I gave my
common Sql Map a
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
Post by Alex Sherwin
namespace of "common", and tried to reference a statement
from another
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
<select id="series" parameterType="map" resultMap="...">
SELECT ...
<where>
<include refid="seriesFilter"/>
</where>
</select>
<sql id="seriesFilter">
...
N.B. The tag I'm using is 'include', and I didn't need to
qualify the
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
sql
id.
Martin
---------------------------------------------------------------------
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
That does work, within the same XML document; I'm trying to
reference a
Post by Alex Sherwin
Post by Jeff Butler
Post by Alex Sherwin
<sql> fragment that is defined in a different XML document
---------------------------------------------------------------------
---------------------------------------------------------------------
--
Sent from my mobile device
---------------------------------------------------------------------
Loading...