views:

201

answers:

1

I have a RecipeJDO that contains a List<IngredientJDO>. RecipeJDO "owns" the ingredients. This has been working well for me for several weeks. Now I'd like to introduce a new class "GroceryListJDO", that references the ingredients owned by various recipes.

When I try to persist a new GroceryListJDO I get the following:

javax.jdo.JDOException: Duplicate property name: ingredients_id_OWN
NestedThrowables:
org.datanucleus.exceptions.NucleusException: Duplicate property name: ingredients_id_OWN
javax.jdo.JDOException: Duplicate property name: ingredients_id_OWN

Seems like there is an issue of "ownership" of the ingredients between RecipeJDO and GroceryListJDO.

I could probably change GroceryListJDO to merely contain a List<String> that acts as a kind of foreign key to IngredientsJDO, but that kind of defeats the purpose of using ORM- I'd have to manually fetch and attach the ingredients in my DAO.

What is the best way to manage JDO collections that need to "attach" to multiple container JDO classes?

This is with JDO on Google App Engine, FWIW.

+1  A: 

Apparently, this is known as an "unowned" relationship, and is not directly supported in GAE. The workaround is what I feared: only one JDO class can own the collection; any other JDOs that reference these objects must persist only Keys, and manage the fetching/saving of the referenced objects manually.

Caffeine Coma