MountainClimb / datanucleus-appengine

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

JPA/JDO entity listener callbacks are not invoked when using Query API #210

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When an entity is loaded using query, postLoad() call back is not invoked.
postLoad() works only with entityManager.find(clazz, id)

As per the JPA specification:
"The PostLoad method is invoked before a query result is returned or accessed 
or before an association is traversed."

Example:

@EntityListeners(value={FooEntityListner.class})
@Entity
public class Foo extends BaseEntity {

}

public class FooEntityListner {
public void postLoad(BaseEntity entity) {

---
}

Query q = getEntityManager().createQuery("select from " + Foo.class.getName());

callback will not be called in above case... however it is invoked if I use
entityManager.find(clazz, id)

Please make this behavior JPA spec compatible.

Original issue reported on code.google.com by sramana...@gmail.com on 8 Jun 2010 at 9:20

GoogleCodeExporter commented 8 years ago
I have exactly the same problems using JDO. I added the LifecycleListener that 
implements LoadLifecycleListener. When I fetch an object by getObjectById the 
postLoad method is invoked. But when I fetch an object (or objects) by a query, 
the postLoad method will not be triggered.

Original comment by gstijn...@gmail.com on 18 Jan 2011 at 4:06

GoogleCodeExporter commented 8 years ago
+1 happens in JDO too.
I see it happening when I have an owned collection and fetch the parent by id, 
then get one of the elements of the owned collection...  When it does the 
lazy-load of the collection, it runs a query and never fires the postLoad 
callback.

I fetched the code revision that's in the app engine sdk from the DataNucleus 
site and stepped through it.  It looks like the problem is in the lazy-loading 
logic that does the child fetch.

Original comment by geoffc on 1 Jul 2011 at 9:38

GoogleCodeExporter commented 8 years ago
SVN trunk adds a test for this, and works fine

Original comment by googleco...@yahoo.co.uk on 17 Jul 2011 at 3:09