我在一个使用hibernate的项目中工作,我的工作是将它切换到openjpa(因为它将被集成到另一个已经使用openjpa的大项目中)。
现在,在运行我的测试时,我收到一条错误消息:
eu.ist_phosphorus.harmony.idb.exceptions.database.DatabaseException: Errors encountered while resolving metadata. See nested exceptions for details.
...
...
at eu.ist_phosphorus.harmony.idb.database.hibernate.Domain.save(Domain.java:878)
at
eu.ist_phosphorus.harmony.idb.database.hibernate.Domain$4.dbOperation(Domain.java:885)
at
eu.ist_phosphorus.harmony.idb.database.TransactionManager.start(TransactionManager.java:108)
... 30 more
...
Caused by: <openjpa-2.2.0-r422266:1244990 fatal user error> org.apache.openjpa.persistence.ArgumentException: Errors encountered while resolving metadata. See nested exceptions for details.
FailedObject: eu.ist_phosphorus.harmony.idb.database.hibernate.Domain@17bf9b45 [java.lang.String]
at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:668)
at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:411)
at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:384)
at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:248)
at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:105)
at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3474)
at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1214)
at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:878)
at eu.ist_phosphorus.harmony.idb.database.hibernate.Domain.save(Domain.java:878)
at eu.ist_phosphorus.harmony.idb.database.hibernate.Domain$4.dbOperation(Domain.java:885)
at eu.ist_phosphorus.harmony.idb.database.TransactionManager.start(TransactionManager.java:108)
... 30 more
Caused by: <openjpa-2.2.0-r422266:1244990 fatal user error> org.apache.openjpa.persistence.ArgumentException: "eu.ist_phosphorus.harmony.idb.database.hibernate.Domain.endpoints<key:class java.lang.Object>" declared that it is mapped by "TNA", but that is a not a field of the related type.
at org.apache.openjpa.meta.ValueMetaDataImpl.getValueMappedByMetaData(ValueMetaDataImpl.java:329)
at org.apache.openjpa.jdbc.meta.ValueMappingImpl.getValueMappedByMapping(ValueMappingImpl.java:121)
at org.apache.openjpa.jdbc.meta.ValueMappingImpl.getColumns(ValueMappingImpl.java:130)
at org.apache.openjpa.jdbc.meta.ValueMappingImpl.resolveMapping(ValueMappingImpl.java:518)
at org.apache.openjpa.jdbc.meta.ValueMappingImpl.resolve(ValueMappingImpl.java:500)
at org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:522)
at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:461)
at org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.java:854)
at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1802)
at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:822)
at org.apache.openjpa.meta.MetaDataRepository.resolveMapping(MetaDataRepository.java:777)
at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:657)
... 40 more
错误由先前为SessionManager.saverOrUpdate()的EntityManager.merge()触发。我知道这些方法有点不同,但是由于错误,它似乎不是一个持久存在的问题,而是在此之前的事情。
从hibernate转到openjpa时,我没有触及实体,我删除了一些@Proxy(lazy = false)注释并更改了api调用的条件。
一方的映射:
@Id
public String getTNA() {
return this.TNA;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fkDomainName")
public Domain getDomain() {
return this.domain;
}
和另一方的映射:
@OneToMany(mappedBy = "domain", fetch = FetchType.LAZY, cascade = { javax.persistence.CascadeType.REMOVE })
@MapKey(name = "TNA")
public Set<Endpoint> getEndpoints() {
return this.endpoints;
}
更新 - 我已经为persist()更改了entityManager.merge()但是我仍然有相同的问题
我也注意到套装不是。这可能会导致问题转移到openjpa吗?
答案 0 :(得分:0)
尝试删除@MapKey。我认为在这种情况下使用它是不正确的。
@MapKey注释用于指定java.util.Map类型的关联的映射键 当map键本身是主键或实体的持久字段或属性时,它是地图的值。