Will future versions of MyBatis officially support multi-threaded or asynchronous ResultMap processing? #3447
Replies: 2 comments 4 replies
-
Hello @worldbright , I don't think they will. |
Beta Was this translation helpful? Give feedback.
-
@worldbright With properly configured nested results, there should not be a reason to issue more than one query. MyBatis can map complex objects based on the results from one query only. If performance is the goal, issuing more than one query for every row is not an ideal case. This can be solved in most cases by good design and using nested results for each query. While i'm not dismissing the request, I believe it should not be necessary in the first place to do that if the design follows good principles. |
Beta Was this translation helpful? Give feedback.
-
For performance reasons, I have avoided using XML-based ResultMap definitions in MyBatis. Instead, I have implemented a custom mechanism that issues multiple queries in parallel—using threads & connections—and manually sets the results onto target objects. This allows me to mimic the multiple select queries in ResultMap, but in a highly performant, concurrent manner.
Since Java 21 introduced Virtual Threads as a preview feature (and now stabilized), the performance and scalability of this approach have improved significantly. It enables lightweight concurrency with minimal overhead, making parallel query execution much more feasible, even at scale.
Of course, I fully understand that MyBatis needs to maintain compatibility with Java 8 and 11, which makes it difficult to adopt Virtual Threads directly at the framework level for now. However, the current design of ResultMap—which executes nested queries sequentially—creates a serious performance bottleneck for applications with deep or complex object graphs (e.g., 1:N:N relationships).
I’m wondering if there are any plans (or openness) to support an optional, thread-enabled (multiple-connections) ResultMap processing model in the future. Even if it relies on physical threads (e.g., Executors, ForkJoinPool, etc.) rather than Virtual Threads or coroutines, the ability to fetch nested results concurrently would provide a massive performance gain in certain scenarios.
I understand that thread safety, transaction management, and potential deadlocks are valid concerns. However, the Java ecosystem has matured significantly in this area. Modern applications are increasingly concurrent by nature, and frameworks like Project Loom have pushed concurrency to the forefront. I believe MyBatis should consider adapting to these evolving patterns.
I realize this may sound like a bold or non-traditional request. Still, I’d love to hear the community’s thoughts on whether something like this could be feasible—either as a core feature or as an opt-in extension.
Beta Was this translation helpful? Give feedback.
All reactions