当前位置:网站首页>The difference between fetchtype lazy and eagle in JPA
The difference between fetchtype lazy and eagle in JPA
2022-07-04 00:34:00 【Teng Qingshan】
Suppose there is 2 Entity , One is University, The other is Student, There are many students in the University , So their relationship is 1 For more than .
University Entities may have some basic attributes , for example id、name、address etc. , And one called students
Set properties of , This attribute returns a list of students from a given University :
University class
public class University {
private String id;
private String name;
private String address;
private List<Student> students;
// setters and getters
}
Now? , When you load universities from the database ,JPA Will load it for you id、name and address Field . But for how to load students , You have two options :
- Load it with the rest of the fields ( That is, eagerly eager), or
- When you call the University getStudents() Methods on demand ( That is, lazily lazy) Load it .
When a university has many students , It is inefficient to load all students together , Especially when they don't need it , under these circumstances , You can declare that you want students to load when they actually need . This is called Delay loading .
This is an example , among students Clearly marked as urgent eager load :
@Entity
public class University {
@Id
private String id;
private String name;
private String address;
@OneToMany(fetch = FetchType.EAGER)
private List<Student> students;
// etc.
}
This is a students Clearly marked as delayed lazy Loaded examples :
@Entity
public class University {
@Id
private String id;
private String name;
private String address;
@OneToMany(fetch = FetchType.LAZY)
private List<Student> students;
// etc.
}
source :
hibernate - Difference between FetchType LAZY and EAGER in Java Persistence API? - Stack Overflow
边栏推荐
- Selenium library 4.5.0 keyword explanation (4)
- What are the application fields of digital twins in industry?
- 【leetcode】374. Guess the size of the number
- P1339 [USACO09OCT]Heat Wave G
- Data storage - interview questions
- [2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
- 不得不会的Oracle数据库知识点(二)
- 想请教一下,十大劵商如何开户?在线开户是安全么?
- Vscode regular match replace console log(.*)
- The culprit of unrestrained consumption -- Summary
猜你喜欢
功能:编写函数fun求s=1^k+2^k +3^k + ......+N^k的值, (1的K次方到N的K次方的累加和)。
How will the complete NFT platform work in 2022? How about its core functions and online time?
Solve the problem that the kaggle account registration does not display the verification code
[cloud native topic -48]:kubesphere cloud Governance - operation - overview of multi tenant concept
URL (data:image/png; Base64, ivborw0k... Use case
Interview script of Software Test Engineer
STM32 GPIO CSDN creative punch in
(Introduction to database system | Wang Shan) Chapter V database integrity: Exercises
Idea a method for starting multiple instances of a service
Eight year test old bird, some suggestions for 1-3 year programmers
随机推荐
It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
Global and Chinese market of breast cancer imaging 2022-2028: Research Report on technology, participants, trends, market size and share
[PHP basics] cookie basics, application case code and attack and defense
Joint examination of six provinces 2017
What are the application fields of digital twins in industry?
Arc 135 supplementary report
Collation of the most complete Chinese naturallanguageprocessing data sets, platforms and tools
[C language] break and continue in switch statement
Introducing Software Testing
Analysis: misunderstanding of choosing WMS warehouse management system
[about text classification trick] things you don't know
[2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
Smart fan system based on stm32f407
Global and Chinese markets for instant saliva testing devices 2022-2028: Research Report on technology, participants, trends, market size and share
Stock price forecast
Is user authentication really simple
Tencent interview: can you find the number of 1 in binary?
ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt
Development and application of fcitx functional plug-ins