Skip to content

Commit

Permalink
Use a transaction scoped EntityManager to set/get a property
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Louis Monteiro <jlmonteiro@tomitribe.com>
  • Loading branch information
jeanouii committed Apr 15, 2021
1 parent da6a340 commit 1dfa11b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/com/sun/ts/tests/jpa/core/entityManager/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.LockModeType;
import jakarta.persistence.ParameterMode;
import jakarta.persistence.PersistenceException;
Expand Down Expand Up @@ -1276,6 +1277,8 @@ public void setPropertyTest() throws Fault {
boolean foundValue = false;

try {
EntityTransaction t = getEntityTransaction();
t.begin();
EntityManager em = getEntityManager();
String expectedKey = "jakarta.persistence.cache.retrieveMode";
CacheRetrieveMode expectedValue = CacheRetrieveMode.USE;
Expand Down Expand Up @@ -1319,6 +1322,15 @@ public void setPropertyTest() throws Fault {
}
} catch (Exception e) {
TestUtil.logErr("Unexpected exception occurred", e);

} finally {
try {
if (getEntityTransaction().isActive()) {
getEntityTransaction().rollback();
}
} catch (Exception fe) {
TestUtil.logErr("Unexpected exception rolling back TX:", fe);
}
}
if (!foundKey || !foundValue) {
throw new Fault("setPropertyTest failed");
Expand Down

0 comments on commit 1dfa11b

Please sign in to comment.