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?

7
  • 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 Apr 1, 2015 at 6: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 1, 2015 at 6: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 Apr 1, 2015 at 7: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 1, 2015 at 9: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. Apr 1, 2015 at 9:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.