Hibernate / MyBatis Interview questions
Explain the execution flow of a MyBatis query from mapper call to result?
A single mapper method call moves through several internal MyBatis layers before returning a mapped Java result, each responsible for a distinct part of translating a typed Java call into an executed SQL statement and back.
After the MapperProxy resolves which MappedStatement corresponds to the called method, the SqlSession hands off to the configured Executor, which first checks the first-level cache before doing any real work; on a cache miss, it obtains a StatementHandler, which in turn uses a ParameterHandler to bind parameters and, after the JDBC driver executes the statement, a ResultSetHandler to map the raw ResultSet back into typed Java objects according to the statement's resultMap or resultType.
This layered pipeline — Executor, StatementHandler, ParameterHandler, ResultSetHandler — is also exactly where MyBatis's plugin/interceptor mechanism hooks in, since each of these four interfaces is a valid target for a custom plugin to intercept and modify behavior at a specific stage of query execution.
More Related questions...