Aha!  Have found the problem.  It's a good one.

The problem was that DataNucleus didn't seem to have replaced the Parent's
ArrayList with its own RDBMS-aware equivalent:

  @Persistent(mappedBy="parent")
  private final List<Child> children = new ArrayList<Child>();

And the reason for that is "final".

So, instead, this should read:

  @Persistent(mappedBy="parent")
  private List<Child> children = new ArrayList<Child>();


Fixing this then discovered a second issue.  JDO/DataNucleus gives us
persistence-by-reachability.  In the addChild() method, you had:

  public void addChild( @Named("Name") String name ) {
    final Child child = newTransientInstance(Child.class);
    child.setName(name);
    addToChildren(child);
    persist(child);
  }

However, attaching the child to the parent will cause it to be persisted,
and then calling persist() once again makes Isis throw an exception.  So, I
changed the code to:

  public void addChild( @Named("Name") String name ) {
    final Child child = newTransientInstance(Child.class);
    child.setName(name);
    addToChildren(child);
    persistIfNotAlready(child);
  }

and it worked.

This might indicate a slight inconsistency in the OS implementations.  Not
sure yet whether that's an issue or not.  One (simple) solution is to
change the semantics of persist() to be persistIfNotAlready()... that
happens to be closer to JDO's semantics, and I don't think would break any
other design assumptions in Isis.

Anyway, you should be good to go.

Cheers
Dan

PS: looking at your code, you might want to check out the CoffeeBytes
plugin along with the Eclipse templates, both on the Isis website [1].


[1]http://incubator.apache.org/isis/ide-support.html

Reply via email to