Your test becomes slow as the database is filled.
Every task run includes:
- Execution of 10,000 find requests of Person instances.
- Execution of 10,000 find requests of Address instances.
- For existing persons - retrieval of the addressSet, which is a mapped by (inverse) collection, and therefore requires a costly query execution
You start feeling the cost of these operations, and mainly the addressSet retrieval when the database is not empty.
A simple action that can improve performance dramatically, is to avoid using mapped by collections:
@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY/*, mappedBy = "person"*/)
private Set<Address> addressSet = new HashSet<Address>();
After converting this mapped by collection to an ordinary collection, the results are:
..................................................2590
..................................................1573
..................................................627
i.e. the 2nd and 3rd runs are faster than the 1st.
If you need to improve performance further, consider replacing the find calls of Address and Person instances with an in memory HashMap and get calls.