未標註的集合屬性需要有 Transient 註釋

在 OpenJPA 中,繼承自 java.util.Collection<E> 介面的屬性不是預設持續性類型,因此這些屬性必須標註才能持續保存。 EclipseLink 有不同的預設行為,其會嘗試將這些屬性持續保存到資料庫中。 如果要維持 OpenJPA 忽略未標註之集合屬性的行為,請在 EclipseLink 中將 javax.persistence.Transient 註釋新增至這些屬性中。

此規則會標示沒有 JPA 註釋且繼承自 java.util.Collection<E> 介面的屬性,包括下列子介面:

在下列實體類別中,規則會標示 collectionFieldlistField 屬性。

import java.util.Collection;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class UnannotatedCollectionEntity {
    @Id private int id; private Collection collectionField; private List listField;}

自動修正將新增 @Transient 註解和匯入語句。

import java.util.Collection;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;

@Entity
public class UnannotatedCollectionEntity {
    @Id private int id; @Transient private Collection collectionField;
    @Transient private List listField;}

如需此問題以及其他 OpenJPA 至 EclipseLink 移轉問題的相關資訊,請參閱 OpenJPA 至 EclipseLink JPA 移轉:對映手冊。