Home > database >  Mybaitis delay loading
Mybaitis delay loading

Time:10-02

use lazy loading point
Online to understand: in the data query, in order to improve the database query performance, as far as possible using a single table query, because single table query table query speed is faster, more
If the query table alone can meet demand and the first query table, when need the correlation information, and associated query, when need the correlation information query this is called lazy loading,
Mybatis resultMap provide lazy-loading functions, through resultMap configuration lazy loading,
Personal understanding: in the use of delay loading time can be in need of a single database table to avoid queries over data table is a waste of time
In open delay before loading, if your SQL statements multi-table join queries, will connect all the table query out together, no matter whether you need the data, but set up delay loading time, will only take out the data that you need, thus greatly save your query (like name, so lazy! LazyLoading)
The first is personal SQL code

Then if you want to set the time delay loading in mybaitis. It is also necessary in XML configuration files, here is the main configuration file (in baidu search mybaitis, 'XML configuration "in the" Settings "there are all kinds of explanation)
LazyLoadingEnabled: the global switch of lazy loading, when opened, all associations are lazy loading, the default for the flase
AggressiveLazyLoading: when open, any method calls can load the object of all attributes, otherwise, each property will be on-demand loaded, the default for the flase
In the case of a master switch to open, the invasive lazy-loading main switch set to flase, will be lazy loading,

When is flase, does not use lazy loading, and invasive lazy loading the invalid
In the case of a master switch to open, the invasive lazy-loading main switch set to flase, will be lazy loading.
, as shown in front of the tag is not query the second SQL query the value, namely the second won't execute SQL

When the switch is set to true, not lazy loading, but will call all method as shown, SQL statements run two

Summary about the lazy loading so much temporarily, if everyone who has the relevant knowledge, or where to write the wrong welcome message below!

CodePudding user response:

The first is me

CodePudding user response:

Knowledge complement
Among them:
One-to-many and many-to-many: we normally use lazy loading
Many-to-one, one-to-one: usually we adopt immediately load
  • Related