Data Nucleus错误:类“具有应用程序标识,并且没有指定objectid-class但还有0个主键字段”

时间:2014-07-15 21:34:21

标签: java jpa datanucleus

调用JPA代码并检索EntityManagerFactory时收到错误:

Caused by: org.datanucleus.metadata.InvalidClassMetaDataException: Class com.analytics.jpa.model.Providers has application-identity and no objectid-class specified yet has 0 primary key fields. Unable to use SingleFieldIdentity.
    at org.datanucleus.metadata.AbstractClassMetaData.determineObjectIdClass(AbstractClassMetaData.java:1415)
    at org.datanucleus.metadata.ClassMetaData.populate(ClassMetaData.java:209)
    at org.datanucleus.metadata.MetaDataManager$1.run(MetaDataManager.java:2806)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.datanucleus.metadata.MetaDataManager.populateAbstractClassMetaData(MetaDataManager.java:2800)
    at org.datanucleus.metadata.MetaDataManager.populateFileMetaData(MetaDataManager.java:2623)
    at org.datanucleus.metadata.MetaDataManager.initialiseFileMetaDataForUse(MetaDataManager.java:1183)
    at org.datanucleus.metadata.MetaDataManager.loadPersistenceUnit(MetaDataManager.java:1046)
    at org.datanucleus.api.jpa.JPAEntityManagerFactory.initialiseNucleusContext(JPAEntityManagerFactory.java:855)
    at org.datanucleus.api.jpa.JPAEntityManagerFactory.initialise(JPAEntityManagerFactory.java:470)
    at org.datanucleus.api.jpa.JPAEntityManagerFactory.<init>(JPAEntityManagerFactory.java:428)
    at org.datanucleus.api.jpa.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:116)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)

我的模型类看起来像这样:

@Entity
@Table(name = "PROVIDERS")
@SequenceGenerator(name = "PROVIDERS_SEQ", sequenceName = "PROVIDERS_SEQ", allocationSize = 1)
public class Providers {

     @Id
     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PROVIDERS_SEQ")
     @Column(name = "PROVIDER_ID")
     private Long providerId;

     @Column(name = "PROVIDER_NAME", nullable = false, length = 1000)
     private String providerName;

     @OneToOne(optional = false, orphanRemoval = true, cascade = CascadeType.ALL,
             fetch = FetchType.EAGER, mappedBy = "provider", targetEntity = Maps.class)
     private Maps map;

     // ... Getters and Setters ...
 }

我已经完成的研究表明,如果您没有指定主键字段,则会出现此错误,但是,我的代码会这样做。我还缺少什么?

修改

DataBucleus.MetaData中的一些其他项目登录DEBUG:

  

Class&#34; com.analytics.jpa.model.Providers&#34;已使用JPA注释指定,​​使用这些注释。

     

忽略字段com.analytics.jpa.model.Providers.providerId的元数据,因为我们已经为属性com.analytics.jpa.model.Providers.providerId提供了MetaData

     

填充所有元数据......

     

Class&#34; com.analytics.jpa.model.Providers&#34; :填充元数据

     

类com.analytics.jpa.model.Providers具有应用程序标识,并且未指定objectid-class,但具有0个主键字段。无法使用SingleFieldIdentity。

编辑2

我使用的是以下版本的Data Nucleus库:

  • datanulceus-core: 3.2.5 4.0.0-release
  • datanucleus-api-jpa: 3.2.4 4.0.0-release
  • datanucleus-rdbms: 3.2.4 4.0.0-release

这是在Windows 7上的JDK 1.7.0_25上的Jetty 7.6.7中运行

0 个答案:

没有答案