2017-06-05 52 views
0

當我嘗試訪問實體中存在的方法中的Lazy加載的@oneToMany關係屬性時,出現以下錯誤。Eclipselink:不支持的操作:[instantiateForUnitOfWorkValueHolder]

錯誤:

Caused by: Exception [EclipseLink-7097] (Eclipse Persistence Services - 2.6.3.v20160428-59c81c5): org.eclipse.persistence.exceptions.ValidationException 
Exception Description: Operation not supported: [instantiateForUnitOfWorkValueHolder]. 
    at org.eclipse.persistence.exceptions.ValidationException.operationNotSupported(ValidationException.java:1496) 
    at org.eclipse.persistence.internal.indirection.ProtectedValueHolder.instantiateForUnitOfWorkValueHolder(ProtectedValueHolder.java:61) 
    at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:160) 
    at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:234) 
    at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:89) 
    at org.eclipse.persistence.indirection.IndirectList.buildDelegate(IndirectList.java:271) 
    at org.eclipse.persistence.indirection.IndirectList.getDelegate(IndirectList.java:455) 
    at org.eclipse.persistence.indirection.IndirectList$1.<init>(IndirectList.java:597) 
    at org.eclipse.persistence.indirection.IndirectList.listIterator(IndirectList.java:596) 
    at org.eclipse.persistence.indirection.IndirectList.iterator(IndirectList.java:555) 
    at com.order.modelGroupBase.getStatus(GroupBase.java:205) 

實體:

@Entity 
@Table(name="GROUP") 
@Customizer(GroupBaseCustomizer.class) 
@Inheritance(strategy=InheritanceType.SINGLE_TABLE) 
@ClassExtractor(GroupClassExtractor.class) 
@InstantiationCopyPolicy 
@Cacheable 
@Cache(alwaysRefresh=true, 
refreshOnlyIfNewer=true, 
expiry=300000,  
coordinationType = CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES) 
public class GroupBase { 

@OneToMany(cascade=CascadeType.ALL, mappedBy="groupBase", targetEntity=Groups.class) 
@PrivateOwned 
private List groups = new ArrayList<>(); 

public OrderGroupStatus getStatus() { 

//error is at this line when I try to iterate.. 
for (Iterator itr = getGroups().iterator(); itr.hasNext();) { 
    Groups relationship = (Groups) itr.next(); 
    //some operation.. 

    }   


} 

} 

我在論壇的EclipseLink白眼,但他們並沒有明確解決這個問題,一些鏈接說這是關係到編織。但在我的應用程序中,我根本沒有編織,我也不打算這樣做。

此代碼在沒有JPA的Eclipselink 2.3.2上正常工作。現在我使用Eclipselink 2.6.3和JPA 2.0以及IBM Websphere 8.5.5.8。

注意:這個問題是隨機發生的,並不是每次都是這樣,而且當創建一個新的對象時也是我所觀察到的。

+1

編織可能已被提及,因爲它需要1:1的懶取得和其他性能優化。除非你有充分的理由不這樣做,否則我會考慮使用它。但是,在這種情況下,由於EclipseLink可以注入自己的列表實現,所以對於1:m和M:M的延遲獲取不需要編織。我之前沒有看到這個錯誤,但快速解決方法(不推薦)是將映射標記爲渴望(默認情況下集合是懶惰的)。它必須與您的緩存設置有關,不允許在GroupBase關係上進行提取。 GroupBase是如何讀取的。 – Chris

+0

另外,如果您現在使用JPA,那麼2.3.2中的'working'是什麼?您是否直接進行1:1轉換,將JPA註釋設置爲以前的EclipseLink設置?如果您在新的EL庫中「按原樣」使用舊的非JPA代碼,它是否有效? Groups是什麼樣子的,如果你把日誌記錄在Finest上會記錄什麼? – Chris

+0

嗨@Chris感謝您關注此問題!在2.3.2中,延遲加載列表的迭代運行良好意味着沒有任何異常拋出。當我轉換爲JPA註釋並升級到2.6.3時,我在迭代延遲加載列表中遇到了這個問題。我沒有使用和ASIS舊代碼,我已經正常pojo類轉換爲實體。日誌記錄不顯示任何有趣的事情,只是打印這個堆棧跟蹤 –

回答

0

經過許多命中和跟蹤並更正了我的延遲加載設置後,我發現在其他實體中的相同實體上使用不同的fetchType可能會在SHARED_CACHE模式下導致此問題。

@OneToMany(cascade=CascadeType.ALL, mappedBy="groupBase", targetEntity=Groups.class) 
@PrivateOwned 
private List groups = new ArrayList<>(); 

默認@OneToMany是延遲訪,但在同一實體的「組」的另一實體我已經配置fetchType急於。

當我將兩種提取類型都設置爲LAZY時,此錯誤停止發生。