Re: Way to use sql in mapper interface, without having to create a corresponding xml mapping file?

2010-05-13 Thread Jeff Butler
It took me a while to figure it out also!

Create your SqlSessionFactory as normal, then add the interfaces manually:

 sqlSessionFactory.getConfiguration().addMapper(SomeMapperInterface.class);

Jeff Butler


On Wed, May 12, 2010 at 4:16 PM, Rick R ric...@gmail.com wrote:
 Larry showed me his cool no xml config setup which I'd love to implement at
 some point.

 For this current project using ibatis3 it's too late to refactor a real lot
 at this stage and we're using your typical sqlMapConfig file.  Overall we
 still prefer to code all of our sql in xml files, but I just recently
 decided to create some sql using the annotation-based approach in an
 interface mapper file.

 The problem (?) is that even though all the sql is in this mapper interface,
 I seem to still have to declare a dummy corresponding mapping xml file just
 to declare the interface namespace (otherwise ibatis at runtime bitches
 about not being able to find the mapping.)  I looked over the ibatis3 pdf
 and under the annotation approach section for using Mappers it doesn't
 really mention that you need the corresponding mapping.xml file, so I'm
 probably just missing something stupid?

 Shouldn't there be a way in the SqlMapConfig to declare Use this interface
 mapper ? Basically I was thinking in the mapper section of the config
 instead of having to use:

 mappers
    mapper resource=mapper-files/metadb/DataReleaseMapper.xml/

 You could also include:

 mappers
    mapper class=com.foobar.mapper.DataReleaseMapper/

 As it is now, I'm having to declare that silly DataReleaseMapper.xml which
 only ends up wrapping my interface Mapper.


 ?xml version=1.0 encoding=UTF-8 ? !DOCTYPE mapper
     PUBLIC -//ibatis.apache.org//DTD Mapper 3.0//EN
     http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd;

  mapper
 namespace=com.foo.dataselector.media.service.mapper.DataReleaseMapper

 /mapper

 My assumption is that I'm missing something obvious:)


-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: Way to use sql in mapper interface, without having to create a corresponding xml mapping file?

2010-05-13 Thread Larry Meadors
He wants to represent that in the xml config.

Larry


On Thu, May 13, 2010 at 2:35 PM, Jeff Butler jeffgbut...@gmail.com wrote:
 It took me a while to figure it out also!

 Create your SqlSessionFactory as normal, then add the interfaces manually:

     sqlSessionFactory.getConfiguration().addMapper(SomeMapperInterface.class);

 Jeff Butler


 On Wed, May 12, 2010 at 4:16 PM, Rick R ric...@gmail.com wrote:
 Larry showed me his cool no xml config setup which I'd love to implement at
 some point.

 For this current project using ibatis3 it's too late to refactor a real lot
 at this stage and we're using your typical sqlMapConfig file.  Overall we
 still prefer to code all of our sql in xml files, but I just recently
 decided to create some sql using the annotation-based approach in an
 interface mapper file.

 The problem (?) is that even though all the sql is in this mapper interface,
 I seem to still have to declare a dummy corresponding mapping xml file just
 to declare the interface namespace (otherwise ibatis at runtime bitches
 about not being able to find the mapping.)  I looked over the ibatis3 pdf
 and under the annotation approach section for using Mappers it doesn't
 really mention that you need the corresponding mapping.xml file, so I'm
 probably just missing something stupid?

 Shouldn't there be a way in the SqlMapConfig to declare Use this interface
 mapper ? Basically I was thinking in the mapper section of the config
 instead of having to use:

 mappers
    mapper resource=mapper-files/metadb/DataReleaseMapper.xml/

 You could also include:

 mappers
    mapper class=com.foobar.mapper.DataReleaseMapper/

 As it is now, I'm having to declare that silly DataReleaseMapper.xml which
 only ends up wrapping my interface Mapper.


 ?xml version=1.0 encoding=UTF-8 ? !DOCTYPE mapper
     PUBLIC -//ibatis.apache.org//DTD Mapper 3.0//EN
     http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd;

  mapper
 namespace=com.foo.dataselector.media.service.mapper.DataReleaseMapper

 /mapper

 My assumption is that I'm missing something obvious:)


 -
 To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
 For additional commands, e-mail: user-java-h...@ibatis.apache.org



-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: Way to use sql in mapper interface, without having to create a corresponding xml mapping file?

2010-05-13 Thread Rick R
On Thu, May 13, 2010 at 4:50 PM, Larry Meadors larry.mead...@gmail.comwrote:

 He wants to represent that in the xml config.



Right. It seems odd that you can manually add the Mapper through Java (as
Jeff has shown), but not through the xml config.


Re: Way to use sql in mapper interface, without having to create a corresponding xml mapping file?

2010-05-13 Thread Clinton Begin
That would be a really simple change.

What I've been really getting used to though is configuring the datasource
in XML, and then using Java for most everything else.

For example, I have this in a class called IbatisConfig:

  final String resource = com/myapp/data/IbatisConfig.xml;
  final Reader reader = Resources.getResourceAsReader(resource);
  final SqlSessionFactory sessionFactory = new
SqlSessionFactoryBuilder().build(reader);
  final Configuration configuration = sessionFactory.getConfiguration();
  TypeAliasRegistry typeAliasRegistry =
configuration.getTypeAliasRegistry();
  typeAliasRegistry.registerAlias(User.class);
  typeAliasRegistry.registerAlias(Project.class);
  typeAliasRegistry.registerAlias(Category.class);
  typeAliasRegistry.registerAlias(Type.class);
  configuration.addMapper(UserMapper.class);
  configuration.addMapper(ProjectMapper.class);
  configuration.addMapper(SessionMapper.class);
  return sessionFactory;

Clinton

On Thu, May 13, 2010 at 5:10 PM, Rick R ric...@gmail.com wrote:



 On Thu, May 13, 2010 at 4:50 PM, Larry Meadors larry.mead...@gmail.comwrote:

 He wants to represent that in the xml config.



 Right. It seems odd that you can manually add the Mapper through Java (as
 Jeff has shown), but not through the xml config.







Re: Way to use sql in mapper interface, without having to create a corresponding xml mapping file?

2010-05-13 Thread Rick R
Ok, cool maybe ill just change to this.

(By the way, I'm searching the archives for this, and it's sort of off-topic
but since you mentioned you create your datasource in XML - I'm curious how
do you declare the pool implementation that you want to use? I know ibatis
comes with a default one (not sure which one) but I was going to use the
latest commons-dbcp pool.)

On Thu, May 13, 2010 at 7:25 PM, Clinton Begin clinton.be...@gmail.comwrote:

 That would be a really simple change.

 What I've been really getting used to though is configuring the datasource
 in XML, and then using Java for most everything else.

 For example, I have this in a class called IbatisConfig:

   final String resource = com/myapp/data/IbatisConfig.xml;
   final Reader reader = Resources.getResourceAsReader(resource);
   final SqlSessionFactory sessionFactory = new
 SqlSessionFactoryBuilder().build(reader);
   final Configuration configuration =
 sessionFactory.getConfiguration();
   TypeAliasRegistry typeAliasRegistry =
 configuration.getTypeAliasRegistry();
   typeAliasRegistry.registerAlias(User.class);
   typeAliasRegistry.registerAlias(Project.class);
   typeAliasRegistry.registerAlias(Category.class);
   typeAliasRegistry.registerAlias(Type.class);
   configuration.addMapper(UserMapper.class);
   configuration.addMapper(ProjectMapper.class);
   configuration.addMapper(SessionMapper.class);
   return sessionFactory;

 Clinton


 On Thu, May 13, 2010 at 5:10 PM, Rick R ric...@gmail.com wrote:



 On Thu, May 13, 2010 at 4:50 PM, Larry Meadors 
 larry.mead...@gmail.comwrote:

 He wants to represent that in the xml config.



 Right. It seems odd that you can manually add the Mapper through Java (as
 Jeff has shown), but not through the xml config.








-- 
Rick R


Re: Way to use sql in mapper interface, without having to create a corresponding xml mapping file?

2010-05-13 Thread Rick R
On Thu, May 13, 2010 at 9:21 PM, Rick R ric...@gmail.com wrote:


 (By the way, I'm searching the archives for this, and it's sort of
 off-topic but since you mentioned you create your datasource in XML - I'm
 curious how do you declare the pool implementation that you want to use? I
 know ibatis comes with a default one (not sure which one) but I was going to
 use the latest commons-dbcp pool.)



Nevermind.. Screw it. I'm doing the whole thing now manually with Java
(including the BasicDataSource setup) and no xml (just some db properties
files). I


Way to use sql in mapper interface, without having to create a corresponding xml mapping file?

2010-05-12 Thread Rick R
Larry showed me his cool no xml config setup which I'd love to implement at
some point.

For this current project using ibatis3 it's too late to refactor a real lot
at this stage and we're using your typical sqlMapConfig file.  Overall we
still prefer to code all of our sql in xml files, but I just recently
decided to create some sql using the annotation-based approach in an
interface mapper file.

The problem (?) is that even though all the sql is in this mapper interface,
I seem to still have to declare a dummy corresponding mapping xml file just
to declare the interface namespace (otherwise ibatis at runtime bitches
about not being able to find the mapping.)  I looked over the ibatis3 pdf
and under the annotation approach section for using Mappers it doesn't
really mention that you need the corresponding mapping.xml file, so I'm
probably just missing something stupid?

Shouldn't there be a way in the SqlMapConfig to declare Use this interface
mapper ? Basically I was thinking in the mapper section of the config
instead of having to use:

mappers
   mapper resource=mapper-files/metadb/DataReleaseMapper.xml/

You could also include:

mappers
   mapper class=com.foobar.mapper.DataReleaseMapper/

As it is now, I'm having to declare that silly DataReleaseMapper.xml which
only ends up wrapping my interface Mapper.


?xml version=1.0 encoding=UTF-8 ? !DOCTYPE mapper
PUBLIC -//ibatis.apache.org//DTD Mapper 3.0//EN
http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd;

 mapper
namespace=com.foo.dataselector.media.service.mapper.DataReleaseMapper

/mapper

My assumption is that I'm missing something obvious:)