Reputation: 1
How to store complex objects? I have an object in its list of child objects in the child object has four list of child objects when calling makePersistent (person) object is not saved. Help!!!!!!!!!!!!
I am call pm.makePersistent(); but Lists
@Persistent
private List<ChoosedElementEntity> choosedElements = new ArrayList<ChoosedElementEntity>();
@Persistent
private List<PleasantElementEntity> pleasantElements = new ArrayList<PleasantElementEntity>();
@Persistent
private List<UnpleasantElementEntity> unpleasantElements = new ArrayList<UnpleasantElementEntity>();
@Persistent
private List<SetViewElementEntity> setViewElements = new ArrayList<SetViewElementEntity>();
not saved!!!
example:
@PersistenceCapable(table = "persons", identityType = IdentityType.APPLICATION)
public class PersonEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private List<OfferEntity> offers = new ArrayList<OfferEntity>();
}
@PersistenceCapable(table = "offers", identityType = IdentityType.APPLICATION)
public class OfferEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private List<ChoosedElementEntity> choosedElements = new ArrayList<ChoosedElementEntity>();
@Persistent
private List<PleasantElementEntity> pleasantElements = new ArrayList<PleasantElementEntity>();
@Persistent
private List<UnpleasantElementEntity> unpleasantElements = new ArrayList<UnpleasantElementEntity>();
@Persistent
private List<SetViewElementEntity> setViewElements = new ArrayList<SetViewElementEntity>();
}
@PersistenceCapable(table = "offer_selections", identityType = IdentityType.APPLICATION)
public class ChoosedElementEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private String code;
@Persistent
private Text cmComments;
}
@PersistenceCapable(table = "offer_selections", identityType = IdentityType.APPLICATION)
public class PleasantElementEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private String code;
@Persistent
private Text cmComments;
}
@PersistenceCapable(table = "offer_selections", identityType = IdentityType.APPLICATION)
public class UnpleasantElementEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private String code;
@Persistent
private Text cmComments;
}
Upvotes: 0
Views: 1517
Reputation: 1048
It appears that you have not properly activated generator primary keys in the JDO. This is not a error of the JDO ?
I found it:
"There is currently a bug preventing owned one-to-many relationships where the parent and the child are the same class, making it difficult to model tree structures. This will be fixed in a future release. You can work around this by storing explicit Key values for either the parent or children."
http://code.google.com/intl/en-EN/appengine/docs/java/datastore/usingjdo.html
I could not wait for the fix, so I have already worked around this issue by having all my entities of this type:
Upvotes: 0
Reputation: 20136
@PersistenceCapable
@Element(dependent = "true")
private Set tags = new HashSet();
makePersistentAll(person)
?pm.close()
. Data is never persisted until you close the handler, ie:
// All objects are manupliated using a pm object
PersitenceManager pm = PMF.instance().getPersistenceManager();
// do work
// Store the changes
pm.close()
Upvotes: 2
Reputation: 1048
It may be a problem in the relationship between the objects? Try done manually save each object from complex objects
Upvotes: 0