Skip to content

Commit abeda66

Browse files
[fix] Restrict eager loading to @OnetoOne and @onetomany relationships (darrachequesne#39)
Previously, a JOIN FETCH was also added when dealing with a relationship that may return multiple lines (@onetomany, for example). Since Hibernate doesn't know how many lines it will need to construct your entities, it fetches a lot of lines and store them in memory, resulting in a big performance hit. In that case, the following warning is displayed: "HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!". That commit thus restricts JOIN FETCH to @OnetoOne and @manytoone relationships.
1 parent 2ef128c commit abeda66

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/org/springframework/data/jpa/datatables/repository/SpecificationFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuild
111111
continue;
112112
}
113113
String[] values = column.getData().split(ESCAPED_ATTRIBUTE_SEPARATOR);
114-
if (root.getModel().getAttribute(values[0])
115-
.getPersistentAttributeType() == PersistentAttributeType.EMBEDDED) {
114+
PersistentAttributeType type =
115+
root.getModel().getAttribute(values[0]).getPersistentAttributeType();
116+
if (type != PersistentAttributeType.ONE_TO_ONE
117+
&& type != PersistentAttributeType.MANY_TO_ONE) {
116118
continue;
117119
}
118120
Fetch<?, ?> fetch = null;

0 commit comments

Comments
 (0)