The Session interface defines a refresh() method. Call this method before calling the get() or load() method. You can get the latest data by calling this method;
How to get the latest data has been explained above. My suggestion is that the session first corresponds to a database transaction, and the execution time of the transaction should be as short as possible. Second, for data that changes elsewhere during the session, the official solution should be to use a lock mechanism. Optimistic locks can be used when a certain amount of transaction failure and rollback can be tolerated. Otherwise, pessimistic locks can be considered. The original poster will provide the actual solution. It’s up to you to weigh which method to use in your application.
It’s like this, so the session is generally very short, because all the caches are gone when the session is closed and reopened
You can use evict() or clear() to refresh the cache within the session
The Session interface defines a refresh() method. Call this method before calling the get() or load() method. You can get the latest data by calling this method;
How to get the latest data has been explained above. My suggestion is that the session first corresponds to a database transaction, and the execution time of the transaction should be as short as possible. Second, for data that changes elsewhere during the session, the official solution should be to use a lock mechanism. Optimistic locks can be used when a certain amount of transaction failure and rollback can be tolerated. Otherwise, pessimistic locks can be considered. The original poster will provide the actual solution. It’s up to you to weigh which method to use in your application.