Skip to content

Commit eacd5b1

Browse files
authored
Update README.md
1 parent cf2c5e8 commit eacd5b1

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33

44
Hibernate is a powerful ORM, but you need to have control over the executed SQL queries to avoid **huge performance problems** (N+1 selects, batch insert not working...)
55

6-
You can enable SQL query logging, this is a great help in dev, but not in production. This tool helps you to count the **executed SQL queries by Hibernate in your integration tests**.
6+
You can enable SQL query logging, this is a great help in dev, but not in production. This tool helps you to count the **executed SQL queries by Hibernate in your integration tests, it can assert L2C statistics too**.
77

88
It consists of just an Hibernate SQL inspector service and a Spring Test Listener that controls it (no proxy around the Datasource).
99

1010
The assertion will work seamlessly whether you're testing Spring repositories or doing HTTP integration tests.
1111

12-
## Example
12+
## Examples
1313

14-
* You just have to add the @AssertHibernateSQLCount annotation to your test and it will verify the SQL statements (SELECT, UPDATE, INSERT, DELETE) count at the end of the test :
14+
### Assert SQL statements
15+
16+
You just have to add the @AssertHibernateSQLCount annotation to your test and it will verify the SQL statements (SELECT, UPDATE, INSERT, DELETE) count at the end of the test :
1517

1618

1719
@Test
@@ -39,14 +41,35 @@ If the actual count is different, an exception is thrown with the executed state
3941
=> '/* insert com.lemick.demo.entity.BlogPost */ insert into blog_post (id, title) values (default, ?)'
4042
=> '/* insert com.lemick.demo.entity.PostComment */ insert into post_comment (id, blog_post_id, content) values (default, ?, ?)'
4143
=> '/* insert com.lemick.demo.entity.PostComment */ insert into post_comment (id, blog_post_id, content) values (default, ?, ?)'
44+
45+
### Assert L2C statistics
46+
47+
It supports assertions on Hibernate level two cache statistics, for checking that your entities are cached correctly and that will stay forever:
48+
49+
@Test
50+
@AssertHibernateL2CCount(misses = 1, puts = 1, hits = 1)
51+
void _create_one_post_and_read_it() {
52+
doInTransaction(() -> {
53+
BlogPost post_1 = new BlogPost("Blog post 1");
54+
blogPostRepository.save(post_1);
55+
});
56+
57+
doInTransaction(() -> {
58+
blogPostRepository.findById(1L); // 1 MISS + 1 PUT
59+
});
60+
61+
doInTransaction(() -> {
62+
blogPostRepository.findById(1L); // 1 HIT
63+
});
64+
}
4265

4366
## How to integrate
4467
1. Import the dependency
4568

4669
<dependency>
4770
<groupId>com.mickaelb</groupId>
4871
<artifactId>hibernate-query-asserts</artifactId>
49-
<version>1.0.0</version>
72+
<version>2.0.0</version>
5073
</dependency>
5174

5275
2. Register the integration with Hibernate, you just need to add this key in your configuration (here for yml):

0 commit comments

Comments
 (0)