0

I'm unable to create a multimap index with the JDO Score class below. If I substitute Object[] for Score everything works fine. I thought the issue was that the Score class was not serializable? What am I missing from the Score class?

Score Class:

@PersistenceCapable(identityType=IdentityType.APPLICATION, detachable="true")
@javax.jdo.annotations.Version(strategy=VersionStrategy.VERSION_NUMBER,column="VERSION",
     extensions={@Extension(vendorName="datanucleus", key="field-name",value="version")})

public class Score implements Serializable {

  private static final long serialVersionUID = -8805789255398748271L;

  @PrimaryKey
  @Persistent(primaryKey="true", valueStrategy=IdGeneratorStrategy.IDENTITY)
  private Key id;

  private Long version;

  @Persistent
  private String uid;

  @Persistent
  private Integer value;
}

Multimap index:

List<Score> rows = new ArrayList(scores);
Multimap<Key, Score> grouped = Multimaps.index(rows,
  new Function<Score, Key>() {

    public Key apply(Score item) {
      return (Key) item.getObjKey();
    }
});
Jared Russell
  • 10,804
  • 6
  • 30
  • 31
user913129
  • 99
  • 2
  • 10
  • What exactly is the problem you're having? – ColinD Aug 26 '11 at 01:32
  • The Multimap index below works with a native Object[]. The code above with the Score class does not. Why doesn't the Score class work in the Multimap index? `List rows = new ArrayList(obj1, obj2, obj3); Multimap grouped = Multimaps.index(rows, new Function() { public Key apply(Object [] item) { return (Key) item.getObjKey(); } });` – user913129 Aug 26 '11 at 02:11
  • Er, that shouldn't work. Arrays don't have a `getObjKey()` method. You need to explain what exactly you mean by "works" or "doesn't work". Compiler error? Exception at runtime? Unexpected results? Your `Score` class doesn't seem to have a `getObjKey()` method either, so I'm not sure what to think. – ColinD Aug 26 '11 at 02:14
  • Score class has a method getObjKey, that's not the issue, I omitted it in this post...sorry. Getting NullPointerException from Multimaps.index(rows, new Function() List rows contains data in the debugger, it is populated via… `PersistenceManager pm = pmf.getPersistenceManager(); pm.getFetchPlan().setDetachmentOptions(FetchPlan.DETACH_UNLOAD_FIELDS); List rows = null; Query q = pm.newQuery(Score.class); rows = (List)q.execute();` Must have a null element in List? If I pass in a an java.lang.Object populated with properties, no exception. – user913129 Aug 26 '11 at 02:47
  • Can you post the stack trace of the `NullPointerException`? – ColinD Aug 26 '11 at 03:00
  • java.lang.NullPointerException at com.google.appengine.repackaged.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:181) at com.google.appengine.repackaged.com.google.common.collect.ImmutableMultimap$Builder.put(ImmutableMultimap.java:148) at com.google.appengine.repackaged.com.google.common.collect.ImmutableListMultimap$Builder.put(ImmutableListMultimap.java:161) at com.google.appengine.repackaged.com.google.common.collect.Multimaps.index(Multimaps.java:1388) – user913129 Aug 26 '11 at 03:28
  • at org.graniteds.example.gae.controllers.TaskController.groupByMultimap(TaskController.java:271) at org.graniteds.example.gae.controllers.TaskController.getleaders(TaskController.java:200) at org.graniteds.example.gae.controllers.TaskController$$FastClassByCGLIB$$d7dffaa6.invoke() at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:628) at org.graniteds.example.gae.controllers.TaskController$$EnhancerByCGLIB$$15b84e4e.getleaders() – user913129 Aug 26 '11 at 03:29
  • Score is a child of User and User appears to be null in the result set returned from the query. – user913129 Aug 26 '11 at 03:41
  • 1
    By the way, it's better to post additional information like the stack trace by editing the question rather than commenting. It helps make the question understandable and you can format it too. – ColinD Aug 26 '11 at 03:46

1 Answers1

3

First of all, if you're going to use Guava you should probably use a real release of Guava rather than code that's repackaged for internal use in app engine.

That said, it looks like (assuming the repackaged code works the same as the current released Guava code) at least one of your Score objects' getObjKey() method must be returning null. ImmutableMultimaps don't allow null keys or values.

ColinD
  • 108,630
  • 30
  • 201
  • 202