fetch = FetchType.EAGER Description


 @ManyToOne(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, targetEntity = NodeLevel.class)
 @JoinColumn(name = "pId", nullable = true)  
 private NodeLevel parentNodeLevel;

The principle is like this:

Load the tree structure , use fetch = FetchType.EAGER to turn off lazy loading


When fetching values ​​in the database, if lazy loading is used, only the data of one layer of nodes will be fetched, and then the session will be closed , so that an error will be reported when fetching the data of the next level: session is closed


If it is EAGER, it means that when this data is retrieved, its associated data is also retrieved and put into memory at the same time.


If it is LAZY, then when this data is retrieved, its associated data is not retrieved. In the same session, when it is used, it can be retrieved (access the database again).


However, outside the session, it cannot be retrieved. When using EAGER, because it is in memory, it can also be retrieved outside the session.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325609252&siteId=291194637