gusgogar / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

instance callbacks not invoked on embedded objects #161

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I created a class with @PersistenceCapable @EmbeddedOnly and had it 
implement StoreCallback (the jdoPreStore method), and embedded into another 
class, which also implements the jdoPreStore method.

What is the expected output? What do you see instead?

I found that the jdoPreStore() method was called on the root object but not 
on the embedded object. I would have expected it to be called on both. 
(However, I was unable to find anything about this in the JDO 
specification.)

What version of the product are you using? On what operating system?

App Engine 1.2.6

Please provide any additional information below.

Original issue reported on code.google.com by bslesinsky on 20 Nov 2009 at 5:24

GoogleCodeExporter commented 9 years ago
Could you please add your code to the bug?  This will ensure that I'm trying to
reproduce the same way.

Thanks.

Original comment by max.r...@gmail.com on 20 Nov 2009 at 5:33

GoogleCodeExporter commented 9 years ago
Here's some example code. I expect that calling storeAFoo() should invoke 
jdoPreStore() on both classes, but it only calls Foo.jdoPreStore().

package scratch;

import java.util.Date;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.EmbeddedOnly;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Embedded;
import javax.jdo.listener.StoreCallback;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.JDOHelper;

public class Example {

  @PersistenceCapable
  @EmbeddedOnly
  static class CommonFields implements StoreCallback {
    @Persistent
    private int version;
    @Persistent
    private Date dateCommitted;

    public void jdoPreStore() {
      System.out.println("CommonFields.jdoPreStore called");
      version++;
      dateCommitted = new Date();
    }
  }

  @PersistenceCapable(identityType = IdentityType.APPLICATION)
  static class Foo implements StoreCallback {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Embedded
    @Persistent
    private CommonFields metadata = new CommonFields();

    public void jdoPreStore() {
      System.out.println("Foo.jdoPreStore called");
    }
  }

  public static void storeAFoo() {
    PersistenceManager pm = PMF.PMF.getPersistenceManager();
    try {
      pm.makePersistent(new Foo());
    } finally {
      pm.close();
    }
  }

  public static class PMF {
    public static final PersistenceManagerFactory PMF =
        JDOHelper.getPersistenceManagerFactory("transactions-optional");
  }
}

Original comment by bslesinsky on 20 Nov 2009 at 10:20

GoogleCodeExporter commented 9 years ago
Thanks for the code.  I've plugged this into a project that uses the DataNucleus
rdbms plugin and I see the same behavior.  DataNucleus core plus the rdbms 
plugin is
the reference implementation of JDO, so in cases where the spec doesn't provide
enough guidance I just try to emulate the behavior of the rdbms plugin.  Since 
app
engine and rdbms are doing the same thing I'm not going to treat this as a bug. 
 You
might consider filing a bug against the DataNucleus project or even the JDO 
spec to
try and get this clarified.

Original comment by max.r...@gmail.com on 20 Nov 2009 at 11:42

GoogleCodeExporter commented 9 years ago
Unfortunately the datanucleus folks have a rather unfriendly-looking issue 
tracker and 
forum. I did find this, which suggests they know about it and don't seem 
particularly 
open to requests:

http://www.jpox.org/servlet/forum/viewthread_thread,3574#21014

If you know somebody over there, perhaps you would have better luck.

Original comment by bslesinsky on 23 Nov 2009 at 10:28