-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider detaching entity while consuming it from Stream #3295
Comments
That isn't going to happen as detaching entities breaks how JPA works. Registering an aspect on JPA's |
Could you explain why detaching entities breaks how JPA works and how to register an aspect on |
Probably stating the obvious, JPA expects attached entities to work as designed (dirty tracking, lazy loading, persisting on transactional commit) |
I think it's worthy to treat specially, because the purpose of |
If you want a reasonable fix, please fix the JPA spec. |
I'm not saying something is wrong have to fix, I'm proposing an enhancement, It's kind of contributing, I apologize if made noise here. |
The main purpose of
Stream
is avoiding return a largeList
which may lead to OOM, but before the transaction finished, the entities still exist in persistence context and cannot be recycled by GC, we need to evict entity manually after it be consumed. Here is a test case verify that:it will output like this:
Spring Data JPA could return
Stream
with.peek(entityManager::detach)
.Or use a StatelessSession to fetch stream, It's Hibernate specific, I think there is an equivalent with EclipseLink, we should migrate if standard StatelessEntityManager is out.
The text was updated successfully, but these errors were encountered: