1

我在我的 Gooogle App Engine 项目中从 JPA 1 迁移到 JPA 2,为此我更改了枚举集合的注释,例如这种情况:

//  @OneToMany(cascade = CascadeType.ALL) // JPA 1
    @ElementCollection(targetClass=PositioningType.class)
    private List<PositioningType> bestPositionings;

PositioningType是一个没有注释的枚举。

该代码给了我以下异常:

javax.persistence.PersistenceException: The MetaData for the element class "com.olympya.datamodel.model.PositioningType" of the collection field "com.olympya.datamodel.model.Player.bestPositionings" was not found.
at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:302)
at org.datanucleus.api.jpa.JPAEntityTransaction.commit(JPAEntityTransaction.java:122)
at com.olympya.Services.mergeUser(Services.java:102)
...
Caused by: org.datanucleus.exceptions.NucleusUserException: The MetaData for the element class "com.olympya.datamodel.model.PositioningType" of the collection field "com.olympya.datamodel.model.Player.bestPositionings" was not found.
at com.google.appengine.datanucleus.scostore.AbstractFKStore.<init>(AbstractFKStore.java:120)
at com.google.appengine.datanucleus.scostore.FKListStore.<init>(FKListStore.java:83)
at com.google.appengine.datanucleus.DatastoreManager.newFKListStore(DatastoreManager.java:472)
at org.datanucleus.store.mapped.MappedStoreManager.getBackingStoreForCollection(MappedStoreManager.java:798)
at org.datanucleus.store.mapped.MappedStoreManager.getBackingStoreForField(MappedStoreManager.java:709)
at org.datanucleus.store.types.sco.backed.ArrayList.<init>(ArrayList.java:99)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...

更新 1

尝试持久化整数集合时,我遇到了同样的异常:

@ElementCollection
@Extension(vendorName = "datanucleus", key = "gae.unindexed", value = "true")
//private List<PositioningType> bestPositionings = new ArrayList<PositioningType>();
private List<Integer> bestPositionings;

结果是:

Caused by: org.datanucleus.exceptions.NucleusUserException: The MetaData for the element class "java.lang.Integer" of the collection field "com.olympya.datamodel.model.Player.bestPositionings" was not found.
at com.google.appengine.datanucleus.scostore.AbstractFKStore.<init>(AbstractFKStore.java:120)
at com.google.appengine.datanucleus.scostore.FKListStore.<init>(FKListStore.java:83)
at com.google.appengine.datanucleus.DatastoreManager.newFKListStore(DatastoreManager.java:472)
at org.datanucleus.store.mapped.MappedStoreManager.getBackingStoreForCollection(MappedStoreManager.java:798)
at org.datanucleus.store.mapped.MappedStoreManager.getBackingStoreForField(MappedStoreManager.java:709)
at org.datanucleus.store.types.sco.backed.ArrayList.<init>(ArrayList.java:99)

未找到Integer的元数据!!!


更新 2

使用 注释该字段@Basic,仅此而已,使其正常工作。不过,仍然在这里等待答案,因为@ElementCollection应该可以工作并且@Basic不应该用于收藏。

4

0 回答 0