当前位置:网站首页>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
边栏推荐
- Pytorch learning notes 5: model creation
- Struct in linked list
- Axure resources and prototype tool Axure RP 9 download
- For loop
- Tencent interview: can you find the number of 1 in binary?
- I would like to ask how the top ten securities firms open accounts? Is it safe to open an account online?
- Is user authentication really simple
- What is the difference between NFT, SFT and dnft? How to build NFT platform applications?
- What is the GPM scheduler for go?
- Is the securities account opened by Caicai for individuals safe? Is there a routine
猜你喜欢

MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query

Unity elementary case notes of angry birds Siki college 1-6
![[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!](/img/28/fc05f2e8d53cf81fd061c799090022.jpg)
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!

MySQL is installed as a Windows Service

2022 system integration project management engineer examination knowledge points: software development model

Investment demand and income forecast report of China's building ceramics industry, 2022-2028
![[NLP] text classification still stays at Bert? Duality is too strong than learning framework](/img/49/1ff6025bdb0445e5638c1451e0b267.jpg)
[NLP] text classification still stays at Bert? Duality is too strong than learning framework

A dichotomy of Valentine's Day

(Introduction to database system | Wang Shan) Chapter V database integrity: Exercises

Introducing Software Testing
随机推荐
Struct in linked list
[PHP basics] session basic knowledge, application case code and attack and defense
What is the potential of pocket network, which is favored by well-known investors?
STM32 GPIO CSDN creative punch in
【leetcode】300. Longest increasing subsequence (dynamic programming, dichotomy)
Gossip about redis source code 82
AI Challenger 2018 text mining competition related solutions and code summary
Introduction to thread pool
NLP pre training technology development
What is the difference between NFT, SFT and dnft? How to build NFT platform applications?
Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
P1656 bombing Railway
想请教一下,十大劵商如何开户?在线开户是安全么?
Five high-frequency questions were selected from the 200 questions raised by 3000 test engineers
Test the influence of influent swacth on the electromagnetic coil of quartz meter
URL (data:image/png; Base64, ivborw0k... Use case
Subgraph isomorphism -subgraph isomorphism
Similarities and differences of text similarity between Jaccard and cosine
MySQL winter vacation self-study 2022 12 (2)