You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I couldn't find an issue pertaining to the issue laid out here. My apologies in advance if this is a duplicate.
Recently we discovered that the default behavior of Repository.findOne(Specification) and Repository.findOne(Example) fetches all data that matches the Specification or Example even though we only 2 matches are necessary to know whether or not more than one record matches the predicate. This has resulted in one of our services going down due to out-of-memory errors due to too many records matching the predicate. All of which were loaded into memory.
I've already addressed the issue in our own code by overriding the repository base class implementation with a custom implementation that puts a maximum on the amount of records to retrieve, but I do think it is useful to report it here regardless.
The code below are the implementations present in the SimpleJpaRepository of the methods mentioned earlier. Of particular notice is TypedQuery<?>.getSingleResult(). Which is called without a prior limit being set through TypedQuery<?>.setMaxResults(int). I'm unaware how other library implementations react when calling the TypedQuery<?>.getSingleResult() method without a limit. However, with the hibernate version I'm using this simply results in a select-query with no limit.
f128375 resolved this issue in 3.0.x (now main). I just backported this fix to 2.7.x and 2.6.x.
Unfortunately, 2.6.x has passed OSS support. While the patch is backported, unless a commercially-paying custom makes a request, no release for that version is presently scheduled. I recommend upgrading to at least Spring Data JPA 2.7.x.
I couldn't find an issue pertaining to the issue laid out here. My apologies in advance if this is a duplicate.
Recently we discovered that the default behavior of
Repository.findOne(Specification)
andRepository.findOne(Example)
fetches all data that matches theSpecification
orExample
even though we only 2 matches are necessary to know whether or not more than one record matches the predicate. This has resulted in one of our services going down due to out-of-memory errors due to too many records matching the predicate. All of which were loaded into memory.I've already addressed the issue in our own code by overriding the repository base class implementation with a custom implementation that puts a maximum on the amount of records to retrieve, but I do think it is useful to report it here regardless.
We used
org.springframework.boot:spring-boot-starter-data-jpa:jar:2.6.9
org.springframework.data:spring-data-jpa:jar:2.6.5
org.hibernate:hibernate-core:jar:5.6.9.Final
The code below are the implementations present in the
SimpleJpaRepository
of the methods mentioned earlier. Of particular notice isTypedQuery<?>.getSingleResult()
. Which is called without a prior limit being set throughTypedQuery<?>.setMaxResults(int)
. I'm unaware how other library implementations react when calling theTypedQuery<?>.getSingleResult()
method without a limit. However, with the hibernate version I'm using this simply results in a select-query with no limit.The text was updated successfully, but these errors were encountered: