由于EclipseLink中的更改跟踪,我们目前的应用程序出现严重减速。问题是自制的,我们不会按原样使用JPA。
我想知道,我如何获得缓存命中(第1级),但不要在变更跟踪中包含这些实体,除非满足某些条件。
// not real code, but close if you decompose the layers and inline methods
public void foo(Long customerId, boolean changeName, String newName) {
/*** check customer valid ***/
// #1 HOW TO discard from change tracking? – Customer won’t get modified!
Customer customer = entityManager.find(Customer.class, customerId);
// some Business Rules
// #2 They should be auto discarded from change tracking because #1 is also discarded)
checkSomething(customer.getAddresses());
checkSomething(customer.getPhoneNumbers ());
…
/*** manipulate customer ***/
// somewhere else in different classes/methods …
if(changeName) {
// #3 HOW TO get Cache hit (1st level) - it was read in #1
// newName should be persisted
customer = entityManager.find(Customer.class, customerId);
customer.setName(newName);
}
}
对#1和#2
使用EclipseLink API是可以的我更喜欢提示。
EclipseLink 2.4.2
二级缓存:已停用
ChangeTrackingType:DEFERRED