Skip to content
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

Enabling lazy loading did not achieve the desired effect #1041

Open
youngledo opened this issue Dec 18, 2024 · 5 comments
Open

Enabling lazy loading did not achieve the desired effect #1041

youngledo opened this issue Dec 18, 2024 · 5 comments

Comments

@youngledo
Copy link

youngledo commented Dec 18, 2024

Using the example code of this project, I enabled lazy loading, but found that it still loaded when starting.

image image

My understanding is that when lazy loading is enabled, the following code will not execute without being called:
image

Here is my simplified code based on the example:

package sample.mybatis.xml;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SampleXmlApplication {

  public static void main(String[] args) {
    SpringApplication springApplication = new SpringApplication(SampleXmlApplication.class);
    springApplication.run(args);
  }

}

Other code has not been actively triggered or called:
image

@youngledo
Copy link
Author

However, it seems to work when I use '@ MapperScan':
image

@youngledo
Copy link
Author

I seem to understand that the mybatis.configuration.lazy-loading-enabled is not used to control the lazy loading of Mapper, but to control the lazy loading of SQL scripts, right?

@harawata
Copy link
Member

Hello @youngledo ,

Yes, in MyBatis, lazy loading means lazily executing nested SELECTs.
https://mybatis.org/mybatis-3/sqlmap-xml.html#nested-select-for-association

@youngledo
Copy link
Author

youngledo commented Dec 19, 2024

OK, but I have a question, why does the configuration not provide lazy loading of Bean, but through "@ MapperScan?

mybatis.lazy-initialization=true is invalid.

@harawata
Copy link
Member

  • Lazy loading is a feature of MyBatis (we call it "the core").
  • Lazy initialization is a feature of Spring.

These two are completely different and unrelated.
And @MapperScan is an annotation provided by MyBatis Spring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants