This repository was archived by the owner on Jan 13, 2023. It is now read-only.
File tree 1 file changed +7
-8
lines changed
jpa-hibernate-tutorial-util/src/main/java/com/bobocode/util
1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -25,17 +25,16 @@ public static void close() {
25
25
}
26
26
27
27
public static void performWithinPersistenceContext (Consumer <EntityManager > operation ) {
28
- EntityManager em = emf .createEntityManager ();
29
- em .getTransaction ().begin ();
30
-
28
+ EntityManager entityManager = emf .createEntityManager ();
29
+ entityManager .getTransaction ().begin ();
31
30
try {
32
- operation .accept (em );
33
- em .getTransaction ().commit ();
31
+ operation .accept (entityManager );
32
+ entityManager .getTransaction ().commit ();
34
33
} catch (Exception e ) {
35
- em .getTransaction ().rollback ();
34
+ entityManager .getTransaction ().rollback ();
36
35
throw new JpaUtilException ("Error performing JPA operation. Transaction is rolled back" , e );
37
36
} finally {
38
- em .close ();
37
+ entityManager .close ();
39
38
}
40
39
}
41
40
@@ -48,7 +47,7 @@ public static <T> T performReturningWithinPersistenceContext(Function<EntityMana
48
47
return result ;
49
48
} catch (Exception e ) {
50
49
entityManager .getTransaction ().rollback ();
51
- throw e ;
50
+ throw new JpaUtilException ( "Error performing JPA operation. Transaction is rolled back" , e ) ;
52
51
} finally {
53
52
entityManager .close ();
54
53
}
You can’t perform that action at this time.
0 commit comments