有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

entityManager上字段异常的java多个可写映射。用日食清除

我们正在定制一个外部JEE项目(没有基本的源代码修改,只有配置和继承)。我遇到了以下例外:

Exception [EclipseLink-48] (Eclipse Persistence Services - 2.6.2.v20151217-774c696): org.eclipse.persistence.exceptions.DescriptorExce
ption
Exception Description: Multiple writable mappings exist for the field [MY_TABLE.ERROR_CODE].  Only one may be defined
 as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[errorCodeString-->MY_TABLE.ERROR_CODE]
Descriptor: RelationalDescriptor(my.package.somwhere.DerivedClass --> [DatabaseTable(MY_TABLE)])

Runtime Exceptions:
---------------------------------------------------------

        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:593)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:305)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:303)
        at org.jboss.as.jpa.container.TransactionScopedEntityManager.createEntityManager(TransactionScopedEntityManager.java:187)
        at org.jboss.as.jpa.container.TransactionScopedEntityManager.getEntityManager(TransactionScopedEntityManager.java:91)
        at org.jboss.as.jpa.container.AbstractEntityManager.clear(AbstractEntityManager.java:331)
        at my.code.some.function.somwhere...

这个问题可能与ERROR_CODE列确实存在多个映射这一事实有关。这是原始映射:

@Entity
@Table("name="MY_TABLE")
public class BaseClass implements Serializable {
    ...
    @Column(name="TRJ_ERROR_CODE")
    private Integer errorCode;
}

被重写,列类型从NUMBER更改为VARCHAR2

@Entity
@DiscriminatorValue("X")
@AttributeOverrides({
        @AttributeOverride(name = "errorCode", column = @Column(name = "TRJ_ERROR_CODE", updatable = false, insertable = false))
})
public class DerivedClass extends BaseClass {
   ...
   @Column(name = "TRJ_ERROR_CODE", length = 200)
   private String errorCodeString;
}
<!--ORM.XML-->
    <entity class="my.package.somwhere.DerivedClass">
        <attributes>
            <transient name="errorCode"/>
        </attributes>
    </entity>

这个问题只有在enitityManager.clear()通话时才会出现。坚持实体的工作没有任何问题。调试eclipselink SessionCustomizer只会显示一个映射——第二个映射来自哪里?我怎样才能禁用原来的一个?我找不到任何与org.eclipse.persistence.mappings.DirectToFieldMapping,而不是OneToManyOneToOne等关系有关的例子

实体管理器是使用以下代码段注入的:

@PersistenceContext(unitName = SomeConstants.PERSISTANCE_JTA_UNIT_CODE, type = PersistenceContextType.TRANSACTION)
private EntityManager entityManager;

共 (0) 个答案