简体   繁体   English

JPA 2.1中的fetchgraph和loadgraph有什么区别?

[英]What's the difference between fetchgraph and loadgraph in JPA 2.1?

How does javax.persistence.fetchgraph differ from javax.persistence.loadgraph when providing an EntityGraph hint to a JPA 2.1 query? 向JPA 2.1查询提供EntityGraph提示时, javax.persistence.fetchgraphjavax.persistence.loadgraph有何区别? The documentation isn't really clear. 该文档还不清楚。

When using fetchgraph all relationships are considered to be lazy regardless of annotation, and only the elements of the provided graph are loaded. 使用fetchgraph无论注释如何,所有关系都被认为是lazy的,并且仅加载所提供图的元素。 This particularly useful when running reports on certain objects and you don't want a lot of the stuff that's normally flagged to load via eager annotations. 当在某些对象上运行报表时,这特别有用,并且您不希望通常标记为通过eager注释加载的很多内容。

If you want to eagerly load entities that are normally loaded via lazy annotation, you may use loadgraph to add entities to the query results that would normally be loaded later, thereby avoiding specific N+1 cases. 如果您想急于加载通常通过lazy注释加载的实体,则可以使用loadgraph将实体添加到查询结果中,这些实体通常会在以后加载,从而避免了特定的N + 1情况。 Relationships that were already flagged as eager will continue to be loaded as usual. 已经标记为eager关系将继续照常加载。

See https://docs.oracle.com/javaee/7/tutorial/persistence-entitygraphs001.htm 参见https://docs.oracle.com/javaee/7/tutorial/persistence-entitygraphs001.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM