The primary objective is to optimize the creation time of the sessionFactory (entityManagerFactory). For the following contexts:
- Execution of integration tests, knowing that we have several hundred or even thousands of them, and the JVM is forked. Each second saved significantly reduces the time for validating all the tests.
- Also, the nightly batch chain, which contains over 300 batches, and each batch starts its own JVM.
- For the startup of the application server as well, but it's more of a development issue because in production, the server is not restarted frequently.
In my test case, I have an environment of 500 entities, and the creation takes 20s. The classpath scan takes half of the time, which is 10s. On my project side, I have implemented a detection of classpath modification by using a checksum of file modification dates, which I store in the wrapper of the serialized scanResult. This allows me to know when I need to refresh it. To serialize, I therefore need ScanResultImpl and its dependencies to be serializable. I will also present you the code that I have implemented in my project. |