开发者

JPA Collection of Embeddables

开发者 https://www.devze.com 2023-01-05 23:25 出处:网络
I\'m trying to persist a collection of embeddable/serializable objects a开发者_如何学Cs one of the fields in my entity.I\'ve seen the trick where you wrap the list in another serializable class and st

I'm trying to persist a collection of embeddable/serializable objects a开发者_如何学Cs one of the fields in my entity. I've seen the trick where you wrap the list in another serializable class and store the whole thing as a lob, but that feels like a hack. As far as I can tell, the jpa way to do this is with an @ElementCollection(targetClass=BlaBlaBla.class) annotation on top of my list. I have annotated my BlaBlaBla class to be Embeddable.

Unfortunately, Appengine gives me this 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) 

Is the serializable class hack really necessary? Any help would be hot.


The @ElementCollection has been introduced in JPA 2.0 while GAE/J currently only supports JPA 1.0. In other words, @ElementCollection is not available.

So either use the serialization hack (I don't like it) or map the association as a OneToMany.

0

精彩评论

暂无评论...
验证码 换一张
取 消