首页 > 解决方案 > 共享类不能引用隔离类

问题描述

我正在添加一个映射到现有实体的全新实体:

@Entity
@IdClass(NewEntityPK.class)
public class NewEntity implements Serializable {
    @Id
    @Column(name="USER_ID", nullable = false, length = 256)
    private String userId;

    @Id
    @ManyToOne
    @JoinColumn(name = "EXISTING_ENTITY_ID", referencedColumnName = "EXISTING_ENTITY_ID", nullable = false)
    private ExistingEntity existingEntity;
}

@Entity
@Cacheable(true)
public class ExistingEntity implements Serializable {
}

部署后,我得到:

异常 [EclipseLink-195] (Eclipse Persistence Services - 2.1.3.v20110304-r9073):org.eclipse.persistence.exceptions.DescriptorException
异常描述:共享类 com.example.model.NewEntity 不得引用隔离类 com。 example.model.ExistingEntity。
映射:org.eclipse.persistence.mappings.ManyToOneMapping[existingEntity]
描述符:RelationalDescriptor(com.example.model.NewEntity --> [DatabaseTable(NEW_ENTITY)])

我知道这是因为ExistingEntity被注释为不可缓存。不幸的是,我不能只启用缓存,因为它在实体图周围级联,所以我也被迫禁用缓存NewEntity

是否有替代方案允许在NewEntity不接触其他实体的情况下保持缓存?如果这很重要,我很可能只需要从 开始获取一级链接关系NewEntity

标签: javajpaeclipselink

解决方案


推荐阅读