Skip to content

Commit 7b42ff2

Browse files
authored
Update README.md
1 parent 381238e commit 7b42ff2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ If the actual count is different, an exception is thrown:
3030
com.lemick.assertions.HibernateStatementCountException:
3131
Expected 2 INSERT but was 1
3232
Expected 1 DELETE but was 0
33+
34+
You can also use the static methods in your test method, but it's more complex because Hibernate will try to delay the flush of your entities states at the end of your application transaction,
35+
36+
Here we call flush manually:
37+
38+
@Test
39+
@Transactional
40+
void create_two_entities() {
41+
BlogPost post_1 = new BlogPost("Post title 1");
42+
blogPostRepository.save(post_1);
43+
entityManager.flush();
44+
assertInsertStatementCount(1);
45+
46+
BlogPost post_2 = new BlogPost("Post title 2");
47+
blogPostRepository.save(post_2);
48+
entityManager.flush();
49+
assertInsertStatementCount(2);
50+
}
3351

3452
## How to integrate
3553
- Register the integration with Hibernate, you just need to add this key in your configuration (here for yml):

0 commit comments

Comments
 (0)