emacarron / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

Mapper instances can be half-loaded and that makes MyBatis-Spring startup work wrong #173

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the MyBatis are you using?
MyBatis 3.0.2 & MyBatis-Spring 1.0.0-RC2

Please describe the problem.  Unit tests are best!
When a problem occurs loading a Mapper xml file if using Spring and the 
MapperFactoryBean the startup process ends without errors. 

What is the expected output? What do you see instead?
An exception that tells what happened. But I see no exception during startup 
and when trying to use a mapper I get the "Mapped Statements collection does 
not contain value for x"

Please provide any additional information below.

Spring tries to load a MapperFactoryBean (this is a mapper injector that also 
registers the mapper to MyBatis). Although the loading fails during the xml 
parsing for any reason MyBatis adds the mapper to its MapperRegistry. As a 
result, the mapper is registered, but there are no mapped statements registered.

The problem comes with Spring because it may attempt to reload the 
MapperFactoryBean again. The second time the load is attempted the 
MapperFactoryBean ends without errors because it does not try to add the mapper 
as it sees that it is already registered.

But there are no mapper statements loaded so when you try to use it you will 
get a "Mapped Statements collection does not contain value for x"

A post was posted on forum. EhCache was configured and a NoClassDefFound error 
was thrown.

I think the easiest way to solve it is removing the mapper if the xml loading 
fails. So the MapperRegistry cannot have "half-mappers"

Original issue reported on code.google.com by eduardo.macarron on 13 Nov 2010 at 10:36

Attachments:

GoogleCodeExporter commented 9 years ago
Can be fixed with this patch. 
It not very clean to catch a Throwable maybe there is a better solution. But 
the case is that using EhCache a NoClassDefFoundError is thrown.

Original comment by eduardo.macarron on 13 Nov 2010 at 12:26

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,

I am getting the same error. What is the fix for that ?

Where can i download the latest one related to the "springloading.patch" ?

Thanks

Original comment by khtsh...@gmail.com on 16 Nov 2010 at 3:49

GoogleCodeExporter commented 9 years ago
Hi khtshyam. If you are using EHCache the problem is solved including sl4j in 
your classpath.

Original comment by eduardo.macarron on 16 Nov 2010 at 5:28

GoogleCodeExporter commented 9 years ago
Cleaner implementation with just 3 minor changes.

Original comment by eduardo.macarron on 22 Nov 2010 at 5:39

Attachments:

GoogleCodeExporter commented 9 years ago
Test updated to mybatis 3.0.3 & mybatis-spring RC3. 

Original comment by eduardo.macarron on 22 Nov 2010 at 9:51

Attachments:

GoogleCodeExporter commented 9 years ago
updated patch after sqlfragment order patch is been applied

Original comment by eduardo.macarron on 26 Nov 2010 at 4:52

Attachments:

GoogleCodeExporter commented 9 years ago
Applied patch in revision 3289.

Original comment by christia...@ircm.qc.ca on 26 Nov 2010 at 7:49

GoogleCodeExporter commented 9 years ago

Original comment by eduardo.macarron on 30 Dec 2010 at 8:43

GoogleCodeExporter commented 9 years ago

Original comment by eduardo.macarron on 3 Mar 2012 at 9:11