Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7941425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:40:05+00:00 2026-06-03T23:40:05+00:00

I’m trying to model my Java app engine objects through list properties for fast

  • 0

I’m trying to model my Java app engine objects through list properties for fast efficient querying. Can I improve this code at all?

I don’t really want to migrate over to Objectify.

Here’s the code to retrieve it:

query = persistenceManager.newQuery(HuddleCreatorIndex.class, ":p.contains(creator)");
List<HuddleCreatorIndex> myCreatorIndexList = (List<HuddleCreatorIndex>) query.execute(KeyFactory.createKey(Contact.class.getSimpleName(), fbUserId));
if (myCreatorIndexList.size() > 0) {
    Set<Long> huddles = myCreatorIndexList.get(0).getHuddles();
    //THIS FOR LOOP DID THE TRICK, why is this necessary?  Never saw it in any examples
    for (Long huddleKey : huddles)
        alist.add(persistenceManager.newObjectIdInstance(Huddle.class, huddleKey));
    Collection<Huddle> huddlesICreated = persistenceManager.getObjectsById(huddles);
    allMyHuddles.addAll(huddlesICreated);
}

Here’s the rest of the supporting code showing how the objects are originally stored, and also the relevant model classes.

This code called to on creation of a Huddle (and this correctly sets up all the objects in the datastore)

txn.begin();
//First, create the Huddle, this main model class
newHuddle.setInvitees(inviteeList);
newHuddle = pm.makePersistent(newHuddle);
huddleId = newHuddle.getId();

//Now create the first index
HuddleIndex newIndex = new HuddleIndex();               
newIndex.setParent(KeyFactory.createKey(Huddle.class.getSimpleName(), newHuddle.getId()));
newIndex.setInvitees(inviteeList);
pm.makePersistent(newIndex);

//And finally, create the other index
Query query = pm.newQuery(HuddleCreatorIndex.class);
query.setFilter(":p.contains(creator)");
List<HuddleCreatorIndex> list = (List<HuddleCreatorIndex>) query.execute(creator.getId());
if (list != null && list.size() > 0) {
    HuddleCreatorIndex thisIndex = list.get(0);
    Set<Key> huddles = thisIndex.getHuddles();
    huddles.add(KeyFactory.createKey(Huddle.class.getSimpleName(), newHuddle.getId()));
    thisIndex.setHuddles(huddles);
} else {
    HuddleCreatorIndex newCreatorIndex = new HuddleCreatorIndex();
    newCreatorIndex.setCreator(creator.getId());
    Set<Long> huddleSet = new HashSet<Long>(1);                   
    huddleSet.add(newHuddle.getId());
    newCreatorIndex.setHuddles(huddleSet);
    pm.makePersistent(newCreatorIndex);
}
txn.commit();

Here’s my actual model object with the real data

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Huddle {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id; 

    private Key creator;
    private String name;
    private Date whenTimeStamp;
    private Date creationTimeStamp;
    private String userIdType;
    private Set<Key> invitees;
    private String status;
    private Set<Key> choices;
    private List<Vote> votes;

    //setters, getters, and constructor omitted
}

My index object to make the list property magic happen

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class HuddleCreatorIndex {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key id; 
    private Key creator;
    private Set<Long> huddles;
    //setters, getters, and constructor omitted
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:40:07+00:00Added an answer on June 3, 2026 at 11:40 pm

    Whats wrong with the code ?

    You have @Persistent plastered all over the place (implied by Googles docs admittedly, but then best not to believe them), you don’t need that … all standard types are by default persistent (as per the JDO spec, and indeed extended by Google’s own code to make their Key class etc as persistent by default). Makes the class look much more normal.

    You’re calling makePersistent, yet the object being persisted is in what “state” ? JDOHelper.getObjectState(obj) tells you. If it is already managed then there is no need to do that … the whole point of that bytecode enhancement process, to detect changes. Obviously a nontransactional update will not happen immediately. You don’t say if using a transaction around that.

    Look in the Log for the retrieve, tells you way more than anyone here can.

    Not using v2.0 of the GAE JDO plugin probably too; anything earlier than that is very old and not maintained.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.