HotswapProjects / HotswapAgent

Java unlimited redefinition of classes at runtime.
GNU General Public License v2.0
2.36k stars 493 forks source link

Issues with MyBatisPlus @Select Annotation and Reload Functionality in Mapper #580

Closed shach1990 closed 1 month ago

shach1990 commented 2 months ago

Versions:

  1. MyBatis 3.5.5
  2. MyBatis Plus 3.4.0
  3. Mybatis-Spring 2.0.5
  4. Spring Boot 2.3.12

When using @Select in the Mapper with corresponding Mapper XML, modifying the SQL in @Select and then reloading works as expected. When using @Select in the Mapper without a corresponding Mapper XML, modifying the SQL in @Select and then reloading does not work. Is it necessary to create a corresponding XML for the Mapper to enable normal reload functionality? Could this be a bug?

skybber commented 2 months ago

@homejim do you please know about it?

shach1990 commented 2 months ago

Additionally, HotswapAgent is compiled based on the latest version of the main branch.

homejim commented 2 months ago

@homejim do you please know about it?

When I added annotation auto-reload to the MyBatis plugin, the situation was verified in the unit test org.hotswap.agent.plugin.mybatis.MyBatisPluginAnnoTest. However, it might be slightly different with MyBatis-Plus? I will attempt to reproduce and address this issue later.

homejim commented 1 month ago

@shach1990 The issue has been fixed; you can download this to run it. https://github.com/homejim/HotswapAgent/releases/download/1.4.2.1-SNAPSHOT/hotswap-agent.jar

shach1990 commented 1 month ago

@homejim Upon verification, it has been confirmed that without XML configuration and Mapper configuration, the MyBatisPlugin and MyBatisPlusPlugin are not being initialized, which causes them not to function as intended. This issue is resolved by initializing these plugins during the ClassLoad event of SqlSessionFactoryBean and MybatisSqlSessionFactoryBean, enabling them to work correctly.