google / google/guice

JpaPersistService.end() doesn't call entityManager.remove() in finally block

Open
#694 5 comments 0 reactions 0 assignees View on GitHub
Component-Persist enhancement imported
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

_From [hristo.sabev](https://code.google.com/u/103460411697921184871/) on March 20, 2012 13:53:45_

This is the JpaPersistService.end() method as copied from the source code:

public void end() {
    EntityManager em = entityManager.get();

    // Let's not penalize users for calling end() multiple times.
    if (null == em) {
      return;
    }

    em.close();
    entityManager.remove();
 }

The call to em.close() could fail sometimes. In my particular case it failed because I tried to save an object with byte[] field having more then 500 bytes. This coused the last line to be skipped. Effectively this thread could no longer be used to serve requests because the begin() method of JpaPersistService would always fail.

The fix is to simply surround the em.close() invocation with try-finally block

_Original issue: http://code.google.com/p/google-guice/issues/detail?id=694_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.