Jpa EclipseLink禁用每个查询的更改跟踪
由于EclipseLink中的更改跟踪,我们目前的应用程序速度严重减慢。问题是我们自己造成的,我们不使用JPA 我想知道如何获得缓存命中(第一级),但除非满足某些条件,否则不要在更改跟踪中包含这些实体Jpa EclipseLink禁用每个查询的更改跟踪,jpa,caching,eclipselink,change-tracking,Jpa,Caching,Eclipselink,Change Tracking,由于EclipseLink中的更改跟踪,我们目前的应用程序速度严重减慢。问题是我们自己造成的,我们不使用JPA 我想知道如何获得缓存命中(第一级),但除非满足某些条件,否则不要在更改跟踪中包含这些实体 // not real code, but close if you decompose the layers and inline methods public void foo(Long customerId, boolean changeName, String newName) {
// 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是可以的
我更喜欢暗示
日食2.4.2
二级缓存:已禁用
ChangeTrackingType:DEFERRED尝试使用查询提示,该提示可以作为属性传递给查找或查询,有关提示的详细信息,请参阅。只读提示应该从共享的二级缓存返回实例,不应该修改该实例。由于未将其添加到第一级EntityManager缓存中,因此任何其他不带提示的读取都将生成/返回托管实例
文档说明这适用于非事务性读取操作,因此我不确定如果EntityManager使用事务性连接进行读取,它将如何工作,因为它不会通过事务使用共享缓存进行读取 谢谢你的回答。不幸的是,我们不使用二级缓存(会话缓存)。使用只读提示可防止在步骤#3中对这些实体进行更改-因此这也不起作用。在初始查找操作之后,您必须考虑复制实体