1
1
package org .hibernate .envers .test .integration .basic ;
2
2
3
3
import java .util .List ;
4
-
5
4
import javax .persistence .EntityManager ;
6
5
7
- import org .hibernate .envers .test .BaseEnversJPAFunctionalTestCase ;
8
- import org .hibernate .envers .test .entities .IntTestEntity ;
9
6
import org .junit .Assert ;
10
7
import org .junit .Test ;
11
8
9
+ import org .hibernate .envers .test .BaseEnversJPAFunctionalTestCase ;
10
+ import org .hibernate .envers .test .entities .IntTestEntity ;
11
+ import org .hibernate .testing .TestForIssue ;
12
+
12
13
/**
13
14
* @author Tomasz Dziurko (tdziurko at gmail dot com)
14
15
*/
15
16
public class TransactionRollbackBehaviour extends BaseEnversJPAFunctionalTestCase {
16
-
17
17
@ Test
18
18
public void testAuditRecordsRollback () {
19
19
// Given
@@ -32,15 +32,39 @@ public void testAuditRecordsRollback() {
32
32
em .getTransaction ().commit ();
33
33
34
34
// Then
35
- List <Number > revisionsForSavedClass = getAuditReader ()
36
- .getRevisions ( IntTestEntity .class , ite2Id );
37
- Assert .assertEquals ( "There should be one revision for inserted entity" ,
38
- 1 , revisionsForSavedClass .size () );
39
-
40
- List <Number > revisionsForRolledbackClass = getAuditReader ()
41
- .getRevisions ( IntTestEntity .class , rollbackedIteId );
42
- Assert .assertEquals ( "There should be one revision for inserted entity" ,
43
- 0 , revisionsForRolledbackClass .size () );
35
+ List <Number > revisionsForSavedClass = getAuditReader ().getRevisions ( IntTestEntity .class , ite2Id );
36
+ Assert .assertEquals ( "There should be one revision for inserted entity." , 1 , revisionsForSavedClass .size () );
37
+
38
+ List <Number > revisionsForRolledbackClass = getAuditReader ().getRevisions ( IntTestEntity .class , rollbackedIteId );
39
+ Assert .assertEquals ( "There should be no revision for rolled back transaction." , 0 , revisionsForRolledbackClass .size () );
40
+ }
41
+
42
+ @ Test
43
+ @ TestForIssue ( jiraKey = "HHH-8189" )
44
+ public void testFlushedAuditRecordsRollback () {
45
+ // Given
46
+ EntityManager em = getEntityManager ();
47
+ em .getTransaction ().begin ();
48
+ IntTestEntity iteToRollback = new IntTestEntity ( 30 );
49
+ em .persist ( iteToRollback );
50
+ em .flush ();
51
+ Integer rollbackedIteId = iteToRollback .getId ();
52
+ em .getTransaction ().rollback ();
53
+
54
+ // When
55
+ em .getTransaction ().begin ();
56
+ IntTestEntity ite2 = new IntTestEntity ( 50 );
57
+ em .persist ( ite2 );
58
+ em .flush ();
59
+ Integer ite2Id = ite2 .getId ();
60
+ em .getTransaction ().commit ();
61
+
62
+ // Then
63
+ List <Number > revisionsForSavedClass = getAuditReader ().getRevisions ( IntTestEntity .class , ite2Id );
64
+ Assert .assertEquals ( "There should be one revision for inserted entity." , 1 , revisionsForSavedClass .size () );
65
+
66
+ List <Number > revisionsForRolledbackClass = getAuditReader ().getRevisions ( IntTestEntity .class , rollbackedIteId );
67
+ Assert .assertEquals ( "There should be no revision for rolled back transaction." , 0 , revisionsForRolledbackClass .size () );
44
68
}
45
69
46
70
@ Override
0 commit comments