Skip to content

Commit

Permalink
Close associated Entity Managers upon Streamer cache reset, fix #341
Browse files Browse the repository at this point in the history
  • Loading branch information
julgus committed Jun 15, 2023
1 parent cf83a11 commit 1a49426
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ default <T> Stream<T> stream(final Projection<T> projection) {
* Resets the Streamer associated with the provided Entity classes.
* <p>
* This will create a new instance of the underlying {@code jakarta.persistence.EntityManager}, removing all entries of the
* associated Entity class from the first-level cache.
* associated Entity class from the first-level cache. The old {@code jakarta.persistence.EntityManager} is closed upon removal from the cache.
*
* In case JPAStreamer was configured with a {@code Supplier<EntityManager>} the lifecycle of the Entity Managers is
* not managed by JPAStreamer, thus use of the method is not permitted and will result in an {@code UnsupportedOperationException}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public void resetStreamer(Class<?>... entityClasses) throws UnsupportedOperation
}
Arrays.stream(entityClasses)
.map(StreamConfiguration::of)
.forEach(streamerCache::remove);
.filter(streamerCache::containsKey)
.forEach(sc -> {
streamerCache.get(sc).close(); // Close Entity Manager
streamerCache.remove(sc);
});
}

@Override
Expand Down

0 comments on commit 1a49426

Please sign in to comment.