mybatis-3 icon indicating copy to clipboard operation
mybatis-3 copied to clipboard

feat: allow `DefaultSqlSessionFactory` to provide a custom `SqlSession`

Open epochcoder opened this issue 10 months ago • 4 comments

Hi Maintainers!

While extending SqlSessionFactoryBuilder allows users to fully customise their implementations of SqlSessionFactory and SqlSession, the drawback is that you cannot use the safe defaults MyBatis provides anymore, which leaves two options:

  • Duplicate (copy/paste) DefaultSqlSession and DefaultSqlSessionFactory, the drawbacks here are that you do not get upstream updates anymore and have to compare and update these files every release.
  • Use reflection, the drawbacks here are that this is quite dirty and suffers from the same problems mentioned above.

I added a minimal test case which shows a structure that would allow the use of the defaults while providing important extension points.

Below is parked for future discussion:

Additionally, allow subclasses of DefaultSqlSession to call selectList(...), which allows providing a system wide result handler if user code did not specify one.

I understand that this is definitely not a common use case, but believe the changes required are so minimal that it would provide a good tradeoff.

PS: note that the result handler is not the only reason here, we do quite some custom work (in our codebase) in the factory and session respectively.

epochcoder avatar Apr 03 '24 10:04 epochcoder