当前位置:网站首页>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
边栏推荐
- Make small tip
- 8. Go implementation of string conversion integer (ATOI) and leetcode
- A method to solve Bert long text matching
- Gossip about redis source code 82
- Yyds dry goods inventory three JS source code interpretation - getobjectbyproperty method
- Idea set class header comments
- Reading notes on how programs run
- P1629 postman delivering letter
- Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
- How will the complete NFT platform work in 2022? How about its core functions and online time?
猜你喜欢
[2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
SPI based on firmware library
Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
Joint examination of six provinces 2017
(Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
Docking Alipay process [pay in person, QR code Payment]
ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt
Regular expressions and text processors for shell programming
功能:编写函数fun求s=1^k+2^k +3^k + ......+N^k的值, (1的K次方到N的K次方的累加和)。
Struct in linked list
随机推荐
[PHP basics] cookie basics, application case code and attack and defense
Eight year test old bird, some suggestions for 1-3 year programmers
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
P1656 bombing Railway
8. Go implementation of string conversion integer (ATOI) and leetcode
(Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
[CSDN Q & A] experience and suggestions
Optimization of for loop
Detailed explanation of the relationship between Zhongtai, wechat and DDD
MySQL winter vacation self-study 2022 12 (1)
UTS | causal reasoning random intervention based on Reinforcement Learning
Selenium library 4.5.0 keyword explanation (4)
Subgraph isomorphism -subgraph isomorphism
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
Docking Alipay process [pay in person, QR code Payment]
【leetcode】374. Guess the size of the number
Stock price forecast
Recommendation of knowledge base management system
From functools import reduce -- see the use of reduce function from typical examples
Speed up the energy Internet of things. What can low-power Internet of things technology represented by Zeta do?