使用@ElementCollection不使用GAA和JPA 2

时间:2012-08-29 15:01:39

标签: google-app-engine jpa jpa-2.0 datanucleus

我在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)

找不到整数的元数据!!!


更新2

使用@Basic注释字段,而不是其他内容,使其正常工作。但是,仍然在等待答案,因为@ElementCollection应该有用,@Basic不应该用于集合。

0 个答案:

没有答案