surinder-insonix / datanucleus-appengine

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

Fetch Groups not being applied for 1:M relationships when using JDOQL Query API #268

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi there,

Fetch groups do not appear to be applied when using the JDOQL Query API when 
using the 2.0.0-final version of the datanucleus-appengine library.  This used 
to work using the 1.0.10 version (with datanucleus core 1.1.5).  Is a new 
approach required when using the new plugin?

To reproduce:

1. Create 4 entities, with one being a parent linked to the other three via 3 
1:M relationships.  Give the parent an 'email' string field that can be queried 
on via JDOQL.  Use JDO annotated classes.

2. Assign the 1:M relations to different fetch groups via annotations on the 
parent.

3. Persist a parent entity and some children for the three 1:M relationships.  
Perform a JDOQL query on the 'email' string field to retrieve the parent 
entity.  Regardless of what fetch group is applied to the PersistenceManager 
for the query, none of the child entities are fetched.

Example - User object (parent) is related to child objects 
Content,MediaBranding and History.  Content is assigned to 'content' fetch 
group.  MediaBranding and History are assigned to 'bits' fetch group.

Persist a User along with related Content,MediaBranding and History.  When 
performing a JDOQL query and specifying the 'bits' fetch group, I am expecting  
the MediaBranding and History children to be fetched.  However, none of the 
children end up being fetched.

User result = null;
try {
    pm.getFetchPlan().addGroup("bits");
    log.info("Groups in fetch plan: " + pm.getFetchPlan().getGroups());
    Query query = pm.newQuery(User.class);           
    query.setFilter("email == emailParam");
    query.declareParameters("java.lang.String emailParam");
    List<User> results = (List<User>) query.execute("hello@site.net");
    assertEquals(1, results.size());
    result = results.get(0);
    pm.makeTransient(result, true);
} finally {
    pm.close();
}

log.info("History: " + result.getUserHistory());
assertNotNull("Should be history children", result.getUserHistory());
assertNotNull("Should be branding children", result.getUserBranding());
assertEquals("Should be 2 history children fetched", 2, 
result.getUserHistory().size());
assertEquals("Should be 2 branding children fetched", 2, 
result.getUserBranding().size());
assertNull("Should be no content child", result.getUserContent());

I have attached a maven project containing my test cases.  It contains two pom 
files - one for the old datanucleus plugin version (1.0.10) and one for the 
2.0.0-final version.  When running against the old version, all tests pass.  
You will have to change the jdoconfig tag in UserTest.java when running against 
the old versions.

Env details (refer to test pom for datanucleus versions):

Environment: Linux - Ubuntu 10.04 LTS : Ubuntu SMP x86_64 GNU/Linux
Appengine version: 1.6.1.1
Datanucleus-appengine version: 2.0.0-final
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

17:28:50.586 [main] DEBUG DataNucleus.Persistence - DataNucleus Persistence 
Factory - Vendor: "DataNucleus"  Version: "3.0.6"
17:28:50.586 [main] DEBUG DataNucleus.Persistence - DataNucleus Persistence 
Factory initialised for datastore URL="appengine" driver="" userName=""
17:28:50.586 [main] DEBUG DataNucleus.Persistence - JDK : 1.6.0_26 on Linux
17:28:50.586 [main] DEBUG DataNucleus.Persistence - Persistence API : JDO
17:28:50.586 [main] DEBUG DataNucleus.Persistence - Plugin Registry : 
org.datanucleus.plugin.NonManagedPluginRegistry
17:28:50.586 [main] DEBUG DataNucleus.Persistence - Standard Options : 
pm-singlethreaded, retain-values, nontransactional-read, 
nontransactional-write, serverTimeZone=UTC
17:28:50.586 [main] DEBUG DataNucleus.Persistence - Persistence Options : 
reachability-at-commit managed-relations(checked) deletion-policy=JDO2
17:28:50.586 [main] DEBUG DataNucleus.Persistence - Transactions : 
type=RESOURCE_LOCAL mode=datastore isolation=read-committed
17:28:50.586 [main] DEBUG DataNucleus.Persistence - Value Generation : 
txn-isolation=read-committed connection=New
17:28:50.586 [main] DEBUG DataNucleus.Persistence - ClassLoading : jdo
17:28:50.586 [main] DEBUG DataNucleus.Persistence - Cache : Level1 (soft), 
Level2 (none, mode=UNSPECIFIED), QueryResults (soft), Collections/Maps

Let me know if you need more information.

Thanks,

Rob.

Original issue reported on code.google.com by hotbitt...@gmail.com on 21 Feb 2012 at 7:02

Attachments:

GoogleCodeExporter commented 8 years ago
I have the exact same issue - thanks @Rob for putting up some example code.

Original comment by christof...@metacdn.com on 22 Feb 2012 at 4:37

GoogleCodeExporter commented 8 years ago
Apparently this doesn't happen with current SVN, as per 
http://stackoverflow.com/questions/9386943/how-to-apply-fetch-groups-using-jdoql
-queries-with-datanucleus-appengine-2-0-0-f

Original comment by googleco...@yahoo.co.uk on 27 Feb 2012 at 9:59