Skip to content

Commit

Permalink
Improve the error message if an EntityManager is provisioned before a…
Browse files Browse the repository at this point in the history
… unit if work is started, to help users transition to the new default that requires an explicit work open (or the legacy option set).

PiperOrigin-RevId: 529465168
  • Loading branch information
sameb authored and Guice Team committed May 4, 2023
1 parent bb54925 commit 3bb74d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 0 additions & 1 deletion extensions/persist/src/com/google/inject/persist/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ java_library(
tags = ["maven_coordinates=com.google.inject.extensions:guice-persist:" + POM_VERSION],
deps = [
"//core/src/com/google/inject",
"//extensions/servlet/src/com/google/inject/servlet",
"//third_party/java/aopalliance",
"//third_party/java/guava/annotations",
"//third_party/java/guava/base",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ public EntityManager get() {
EntityManager em = entityManager.get();
Preconditions.checkState(
null != em,
"Requested EntityManager outside work unit. "
+ "Try calling UnitOfWork.begin() first, or use a PersistFilter if you "
+ "are inside a servlet environment.");
"Requested EntityManager outside work unit. As of Guice 6.0, Guice Persist doesn't"
+ " automatically begin the unit of work when provisioning an EntityManager. To"
+ " preserve the legacy behavior, construct the `JpaPersistModule` with a"
+ " `JpaPersistOptions.builder().setAutoBeginWorkOnEntityManagerCreation(true).build()`."
+ " Alternately, try calling UnitOfWork.begin() first, or use a PersistFilter if you"
+ " are inside a servlet environment.");

return em;
}
Expand Down

0 comments on commit 3bb74d7

Please sign in to comment.