views:

34

answers:

1

I'm trying to persist a collection of embeddable/serializable objects as 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.

+1  A: 

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.

Pascal Thivent