1

I'm new to the subject so pardon me if I am missing or misunderstanding something.

I'm using JDO 3.1rc1 and DataNucleus 3.2.7.

This is my data class (kept it short as much as possible):

@PersistenceCapable
@FetchGroup(name="dailyAvailableMenuItemsGroup", members={@Persistent(name="_id"), @Persistent(name="daily"), @Persistent(name="available"), @Persistent(name="available_Mode")})
public class MenuItem
{
    ... // Many @Persistent fields here, most are String or Boolean type
}

And here is the code where I attempted to retrieve partial fields here

pm.getFetchPlan().clearGroups();
pm.getFetchPlan().addGroup("dailyAvailableMenuItemsGroup");
Query q = pm.newQuery(MenuItem.class);
@SuppressWarnings("unchecked")
List<MenuItem> menuItems = (List<MenuItem>) q.execute();

However when looping through the results, it appears that all the fields have values, instead of null as I would have expected. I also tried the dynamic way of doing it thinking it could be an issue with my annotations but to no avail. Any idea where I have gone wrong?

marcolopes
  • 9,232
  • 14
  • 54
  • 65
CyberMew
  • 1,159
  • 1
  • 16
  • 33
  • 1
    And the SQL invoked is? You do know that a FetchPlan is a *hint* to the provider of what should be fetched ? and that does "work" in my experience – Neil Stockton Apr 01 '15 at 06:24
  • In the console logs I'm seeing this: SELECT FROM com.cybermew.data.MenuItem I thought the correct statement should be something like SELECT _id, daily, available FROM com.cybermew.data.MenuItem instead. Oh I didn't know that it's supposed to be a hint. Hmm, weird that the hint wasn't being used.. – CyberMew Apr 01 '15 at 06:54
  • 1
    In the DataNucleus log you will see SQL (assuming you have DEBUG level). You referred to JDOQL. Until you know the SQL invoked you can't assume anything ... maybe an object came from the L1 or L2 cache with those other fields loads? The log tells you such things – Neil Stockton Apr 01 '15 at 07:08
  • I'm unable to log DataNucleus.Query for some reason (they aren't showing up, only DataNucleus.Enhancer/.MetaData related operations are), hence I couldn't see the actual commands that's being invoked to the database. Besides FetchPlans, are there other ways to query only for specific column fields? – CyberMew Apr 01 '15 at 09:29
  • Just set the result clause of the JDOQL, and it returns those field values rather than objects. Other than that, configure the logging, its basic Log4J or java.util.logging. – Neil Stockton Apr 01 '15 at 09:30
  • Thanks for the suggestion. I guess I have to use setResult and use a map to get it out. I wonder if it's any faster compared to fetch plans? As for the logging I'm using Log4J but for some reason during runtime it doesn't output to the file. Thank you very much again for your help. – CyberMew Apr 01 '15 at 11:45
  • http://www.datanucleus.org/products/accessplatform_4_0/logging.html category DataNucleus.Datastore.Native – Neil Stockton Apr 01 '15 at 13:15

0 Answers0