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 Joram Barrez <jo...@gmail.com> on 2010/04/30 09:58:07 UTC
How to programmatically add an xml mapping file to a Configuration?
Hi group,
I know that it is possible add a Mapper class to the configuration
when programnatically creating a SqlSessionFactory:
configuration.addMapper(MyMapper.class);
As stated in the docs, this will also look for a MyMapper.xml on the classpath.
However, I only have XML mapping files (so no mapper class). How can I
add these to a Configuration? I can't seem to find the right method.
Regards,
Joram
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
Re: How to programmatically add an xml mapping file to a
Configuration?
Posted by Martin Ellis <el...@gmail.com>.
On 30 April 2010 08:58, Joram Barrez <jo...@gmail.com> wrote:
> However, I only have XML mapping files (so no mapper class). How can I
> add these to a Configuration? I can't seem to find the right method.
I've found this in my code, which seems a little complicated, but it
gets the job done.
It's code I wrote when I first started using iBATIS (early 3.0 betas),
so there might well be an easier way.
private static void addSqlMappings(Configuration conf) {
Map<String, XNode> xmlMap = new HashMap<String, XNode>();
Reader map;
try {
map = Resources.getResourceAsReader("package/name/mapper.xml");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
XMLMapperBuilder xmlParser =
new XMLMapperBuilder(map, conf, "mapper.xml", xmlMap,
ibatisNamespace);
xmlParser.parse();
}
Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org