当前位置:网站首页>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
边栏推荐
- From functional testing to automated testing, how did I successfully transform my salary to 15K +?
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- URL (data:image/png; Base64, ivborw0k... Use case
- Correlation analysis summary
- Gossip about redis source code 82
- Sorry, Tencent I also refused
- The culprit of unrestrained consumption -- Summary
- P1629 postman delivering letter
- 功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
- Analysis on the scale of China's smart health industry and prediction report on the investment trend of the 14th five year plan 2022-2028 Edition
猜你喜欢
Introducing Software Testing
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something
Generic
Iclr2022: how does AI recognize "things I haven't seen"?
Unity elementary case notes of angry birds Siki college 1-6
Regular expressions and text processors for shell programming
STM32 key light
What is the Valentine's Day gift given by the operator to the product?
[C language] break and continue in switch statement
随机推荐
Generic
Solve the problem that the kaggle account registration does not display the verification code
Arc 135 supplementary report
P3371 [template] single source shortest path (weakened version)
Optimization of for loop
MySQL winter vacation self-study 2022 12 (1)
From functools import reduce -- see the use of reduce function from typical examples
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
Is the account opening of Guoyuan securities really safe and reliable
Idea set class header comments
[cloud native topic -48]:kubesphere cloud Governance - operation - overview of multi tenant concept
A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders
For loop
Global and Chinese market of glossometer 2022-2028: Research Report on technology, participants, trends, market size and share
Selenium library 4.5.0 keyword explanation (I)
What does redis do? Redis often practices grammar every day
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
Selenium library 4.5.0 keyword explanation (4)
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
AI Challenger 2018 text mining competition related solutions and code summary