1

I would like to know if the following is possible in JDO.

I have a 1-N relationship between a Parent and a Child class. So my classes look like

@PersistenceCapable 
public class Parent { 

    @Persistent 
    private String name; 

    @Elements(mappedBy = "parent", dependent = "true") 
    private List<Children> children; 
}

@PersistenceCapable 
public class Child { 

    @Persistent 
    private String name; 

    @Persistent
    private Parent parent;
}

Cascading deletes work fine. I can delete a parent and all its children will be removed from the data store.

If I query the data store for a particular child and have that query delete it, then the child is removed from the table of Child objects but its Parent's list of children will contain a null entry.

I guess this is a fairly dumb question but is there a way to get JDO to update the parent's list on deletion of a child or do I have to do this myself?

Thanks for your replies.

tilo
  • 14,009
  • 6
  • 68
  • 85
Don'tWantTo
  • 155
  • 3
  • 8
  • Provide details of datastore used, JDO implementation, actual persistence code that does the delete, log entries – DataNucleus Jul 21 '11 at 17:19
  • DataNucleus Access Platform 2.2 with the following jars asm-3.1.jar, db4o-7.12.126.14142-all-java5.jar, jdo-api-3.1-SNAPSHOT-20110223.jar, datanucleus.core-2.2.3.jar, datanucleus-enhancer-2.1.3-jar, datanucleus-db4o.2.1.2.jar. So I'm using DB4O too. – Don'tWantTo Jul 22 '11 at 10:32
  • String name = "name"; transaction.begin(); Query query = manager.newQuery(Child.class, "this.name == name"); query.declareParameters("java.lang.String name"); query.setUnique(true); query.deletePersistentAll(name); transaction.commit(); – Don'tWantTo Jul 22 '11 at 10:36
  • Obviously a db4o-specific issue and how it interfaces with the DataNucleus plugin, and that plugin is not maintained ... db4o were invited to update it but so far haven't done anything. – DataNucleus Jul 22 '11 at 10:50
  • Thanks very much. Which datastore would you recommend instead? – Don'tWantTo Jul 22 '11 at 11:33
  • Well its your application so you need to decide based on what it needs to do. Obviously there is RDBMS, but also some NoSQL stores (MongoDB, HBase) are useful. Depends on the use-case. – DataNucleus Jul 22 '11 at 12:28

1 Answers1

-1

I recommend db4o without the DataNucleus layer. It is just getting in the way of a better performing soluton. We've done testing and found that if you use db4o directly it performs much better and uses less resources.

Robert
  • 368
  • 2
  • 8