-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IncompleteElementException occurs temporarily when Spring Application starts #696
Comments
Hello @be-hase , It seems logically impossible to guarantee 'no-error' with your usage (i.e. a thread calling a statement while the main thread is loading mappers). I'm not a Spring guru, but there might be some Spring side solution which ensures the background thread waits for the main thread's task completion. |
@harawata However, in my opinion, incomplete instances should not be registered in DI. BTW, should I make an issue here and have a discussion? I think it's a spring integration issue, not a mybatis-core issue. |
Please give me some time to think about this. |
If my understanding is correct, the problem is... BTW, adding eager loading feature to the mybatis-spring is easier than changing mybatis-core. I want an eager loading option~ |
Having incomplete statements is part of the normal process and it could happen even when the mappers are loaded by a single thread. Let's say there are two mappers: public interface FirstMapper {
@Select("...")
@ResultMap("mapper.SecondMapper.someResultMap")
SomePojo select1();
}
public interface SecondMapper {
@Select("...")
@Results(id = "someResultMap", ...)
SomePojo select2();
} Assuming that the In a multi-threaded situation, another thread could call The fundamental difficulty is that there is no way to know if all mappers are loaded or not (note that I explored an idea of blocking the I'll transfer the issue to MyBatis-Spring as it seems to be the main concern here. |
by the way, I came up with an idea. |
MyBatis version
mybatis: 3.5.10
mybatis-spring-boot-starter: 2.2.2
org.mybatis:mybatis-spring:2.0.7
Database vendor and version
mysql 5.7.27
(But this issue is not related to mysql)
Test case or example project
It's a little difficult, so let me just report first.
If my explanation is confusing, I'll do my best to write a small sample code.
Steps to reproduce
In my application, I use mapper definition with annotation like below.
When loading this Mapper Interface, the order returned by Java
Class.getMethods
is undefined, soincompleteMethods
occurs in this process.https://github.com/mybatis/mybatis-3/blob/84cc6a1c1682fd5619348c6eb3a6378f69483ddf/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java#L123-L136
Subsequent
parsePendingMethods
resolve thisincompleteMethods
.https://github.com/mybatis/mybatis-3/blob/84cc6a1c1682fd5619348c6eb3a6378f69483ddf/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java#L138
However, other mepper Interface methods may be executed at other threads before
incompleteMethods
are resolved.At this time, an error(
IncompleteElementException
) will occur becauseincompleteMethods
exists.https://github.com/mybatis/mybatis-3/blob/84cc6a1c1682fd5619348c6eb3a6378f69483ddf/src/main/java/org/apache/ibatis/session/Configuration.java#L848-L853
https://github.com/mybatis/mybatis-3/blob/84cc6a1c1682fd5619348c6eb3a6378f69483ddf/src/main/java/org/apache/ibatis/session/Configuration.java#L918-L925
Normally, all DI of spring is done in main thread.
However, if we prepare an instance that executes Mapper Interface in the background thread in DI processing, we will encounter the above problem.
Expected result
The method call of Mapper Interface succeeds without error.
Actual result
_
The text was updated successfully, but these errors were encountered: