I have a common database that is used by two different applications (different technologies, different deployment servers, they just use the same database).
Let's call them application #1
and application #2
.
Suppose we have the following scenario:
- the database contains a table called items (doesn't matter its content)
application #2
is developed in Spring Boot and it is mainly used just for reading data from the databaseapplication #2
retrieves an item from the databaseapplication #1
changes that itemapplication #2
retrieves the same item again, but the changes are not visible
What I understood by reading a lot of articles:
- when
application #2
retrieves the item, Hibernate stores it in the first level cache - the changes that are done to the item by
application #1
are external changes and Hibernate is unaware of them, and thus, the cache is not updated (same happens when you do a manual change in the database) - you cannot disable Hibernate's first level cache.
So, my question is, can you force Hibernate into refreshing the entities every time they are read (or make it go into the database) without explicitly calling em.refresh(entity)
? The problem is that the business logic module from application1
is used as a dependency in application1
so I can only call service methods (i.e. I don't have access to the entityManager
or session
references).