我正在尝试将可嵌入/可序列化对象的集合作为我的实体中的一个字段。我见过将列表包装在另一个可序列化类中并将整个事物存储为 lob 的技巧,但这感觉就像是 hack。据我所知,执行此操作的 jpa 方法是在我的列表顶部使用 @ElementCollection(targetClass=BlaBlaBla.class)
注释。我已将我的 BlaBlaBla 类注释为可嵌入。
不幸的是,Appengine 给了我这个异常(exception):
javax.persistence.PersistenceException: Class "data.Contact" has collection field "properties" and this has no mapping in the table for the element class "data.EntityReference"
org.datanucleus.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java: 264)
org.datanucleus.jpa.EntityTransactionImpl.commit(EntityTransactionImpl.java: 122)
org.datanucleus.store.appengine.jpa.DatastoreEntityTransactionImpl.commit(DatastoreEntityTransactionImpl.java: 55)
可序列化类 hack 真的有必要吗?任何帮助都会很热。
最佳答案
@ElementCollection
已在 JPA 2.0 中引入,同时 GAE/J currently only supports JPA 1.0 .换句话说,@ElementCollection
不可用。
所以要么使用序列化 hack(我不喜欢它)要么将关联映射为 OneToMany
。
关于java - JPA 可嵌入物集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3180910/