根据我的理解,交易完成后不会立即刷新。它们位于内存中的缓存中,并且仅在 EntityManager 确定这样做具有成本效益时才被写入数据库。我相信在这种情况下会使用 L1 缓存,但如果我错了,请纠正我。
我的问题是,在分布式环境中,持久性上下文使用的缓存是分布式的吗?
根据我的理解,交易完成后不会立即刷新。它们位于内存中的缓存中,并且仅在 EntityManager 确定这样做具有成本效益时才被写入数据库。我相信在这种情况下会使用 L1 缓存,但如果我错了,请纠正我。
我的问题是,在分布式环境中,持久性上下文使用的缓存是分布式的吗?
L1 cache (session cache, persistence context) always works the same way, no matter wheteher your environment is distributed or not. Session cache belongs to a session, and you can have multiple sessions, either on the same machine or on different machines, so that it doesn't matter.
In distributed environment you need to care about the second level cache, if you use it.
If you run your application in a cluster, you need to use cluster-capable L2 cache implementation, if you JPA provider supports it (see, for example, 21.2. The Second Level Cache from Hibernate documentation).
If you have other applications accessing the same database, you need to carefully configure caching strategies to avoid inconsistency in critical cases and tolerate possible inconsistency in other cases.