Tags: programming java guice
I discovered that the guice/mybatis combination requires that the DAO configuration be a singleton. That makes sense. By default every time you ask guice for an instance it creates a new one. That also makes sense.
What doesn’t make sense is why the MybatisModule isn’t annotated with @Singleton as documented here
It’s up to the programmer configuring the data source to do it, which is odd. What’s also odd is that when you use the default Mybatis connection pool everything’s fine when not using a singleton. If you try to use c3p0 or bonecp without singleton, however, you’ll find that mybatis opens a block of new connections for every query.