当前位置:网站首页>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
边栏推荐
- system. Exit (0) and system exit(1)
- 挖财帮个人开的证券账户安全吗?是不是有套路
- STM32 key light
- Version rollback revert don't reset better reset must be forced
- SPI based on firmware library
- Kubedl hostnetwork: accelerating the efficiency of distributed training communication
- 8. Go implementation of string conversion integer (ATOI) and leetcode
- Solution to the impact of Remote Code Execution Vulnerability of log4j2 component on December 9, 2021
- 老姜的特点
- How to trade spot gold safely?
猜你喜欢

Solve the problem that the kaggle account registration does not display the verification code

Is user authentication really simple

Unity elementary case notes of angry birds Siki college 1-6

What is the Valentine's Day gift given by the operator to the product?

Tencent interview: can you find the number of 1 in binary?
![Several ways to set up a blog locally [attach relevant software download links]](/img/2f/51a09d9ef71065319ed90306517854.jpg)
Several ways to set up a blog locally [attach relevant software download links]

Collation of the most complete Chinese naturallanguageprocessing data sets, platforms and tools

Kubedl hostnetwork: accelerating the efficiency of distributed training communication

What is the GPM scheduler for go?

Recommendation of knowledge base management system
随机推荐
[2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
Global and Chinese market of glossometer 2022-2028: Research Report on technology, participants, trends, market size and share
For loop
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
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
Bodong medical sprint Hong Kong stocks: a 9-month loss of 200million Hillhouse and Philips are shareholders
Idea a method for starting multiple instances of a service
Why use get/set instead of exposing properties
China standard gas market prospect investment and development feasibility study report 2022-2028
It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
Test the influence of influent swacth on the electromagnetic coil of quartz meter
不得不会的Oracle数据库知识点(二)
[software testing] you haven't mastered these real interview questions of big companies?
Advanced C language - pointer 2 - knowledge points sorting
Selenium library 4.5.0 keyword explanation (4)
挖财帮个人开的证券账户安全吗?是不是有套路
Similarities and differences of text similarity between Jaccard and cosine
The difference between objects and objects
[CSDN Q & A] experience and suggestions
AI Challenger 2018 text mining competition related solutions and code summary