Error querying a enum field : BasicBSONList can only work with numeric keys, not: [className]

1,005 views
Skip to first unread message

ismet

unread,
Jul 13, 2012, 7:54:49 AM7/13/12
to mor...@googlegroups.com
Hi,
I got an error while querying a enum field which seems to me odd.

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [className]
    at com.statu.alarga.common.server.dao.CrewDaoImpl.findAllActive(CrewDaoImpl.java:118)
    at com.statu.alarga.common.server.actionhandler.GetAllCrewActionHandler.execute(GetAllCrewActionHandler.java:23)
    at com.statu.alarga.common.server.actionhandler.GetAllCrewActionHandler.execute(GetAllCrewActionHandler.java:1)
    at com.statu.alarga.common.server.AbstractServiceImpl.execute(AbstractServiceImpl.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1097)
    at com.statu.alarga.common.server.RequestFilter.doFilter(RequestFilter.java:24)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [className]
    at com.google.code.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:149)
    at com.google.code.morphia.mapping.Mapper.readMappedField(Mapper.java:543)
    at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:520)
    at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:272)
    at com.google.code.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:66)
    at com.google.code.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:53)
    at com.google.code.morphia.query.MorphiaIterator.next(MorphiaIterator.java:48)
    at com.google.code.morphia.query.QueryImpl.asList(QueryImpl.java:258)
    at com.statu.alarga.common.server.dao.CrewDaoImpl.findAllActive(CrewDaoImpl.java:109)
    ... 33 more
Caused by: java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [className]
    at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:161)
    at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:152)
    at org.bson.types.BasicBSONList.get(BasicBSONList.java:104)
    at com.google.code.morphia.mapping.DefaultCreator.getClass(DefaultCreator.java:78)
    at com.google.code.morphia.mapping.DefaultCreator.createInstance(DefaultCreator.java:48)
    at com.google.code.morphia.mapping.EmbeddedMapper.readMapOrCollectionOrEntity(EmbeddedMapper.java:232)
    at com.google.code.morphia.mapping.EmbeddedMapper.readCollection(EmbeddedMapper.java:178)
    at com.google.code.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:122)
    ... 41 more

my method is very simple

@Override
  public List<Crew> findAllActive() throws AlargaException {
    try {

      Query<Crew> query = createQuery().field("accountStatus")
          .equal(AccountStatus.Active);

      QueryResults<Crew> find = dao.find(query);

List<Crew> asList = find.asList();

      // sort the result
      // bad mongo ahhhh!!
      Collections.sort(asList, new CrewComparator());

      return asList;

    } catch (Exception e) {
        e.fillInStackTrace();
        e.printStackTrace();
      throw new AlargaException(getClass().getSimpleName() + "[findAllActive] - " + e.toString());
    }
  }

the generated query is
{ "accountStatus" : "Active"}

which is fine, i tried it on with jmongobrowser and its successful.

My crew object is like this

@Entity
public class Crew implements Serializable {

  /**
   * The key provider that provides the unique ID of a Crew.
   */
  public static final ProvidesKey<Crew> KEY_PROVIDER = new ProvidesKey<Crew>() {
    public Object getKey(Crew item) {
      return item == null ? null : item.id;
    }
  };

  @Id
  public ObjectId id;

  @Reference
  private List<Comment> comments = new ArrayList<Comment>();

  public ObjectId avatarId;

  public Date dateModified;

  /* Name */

  public String firstName;

  public String lastName;

}

Anybody has an idea about this situation i would really appreciate it, anybody ever encounter such en error?

ismet

unread,
Jul 15, 2012, 3:58:17 AM7/15/12
to mor...@googlegroups.com
I guess nobody encountered this problem before?

On Friday, July 13, 2012 11:54:49 AM UTC, ismet wrote:
> Hi,
> I got an error while querying a enum field which seems to me odd.
>
> java.lang.RuntimeException: java.lang.RuntimeException: java.lang.<WBR>IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [className]
>     at com.statu.alarga.common.<WBR>server.dao.CrewDaoImpl.<WBR>findAllActive(CrewDaoImpl.<WBR>java:118)
>     at com.statu.alarga.common.<WBR>server.actionhandler.<WBR>GetAllCrewActionHandler.<WBR>execute(<WBR>GetAllCrewActionHandler.java:<WBR>23)
>     at com.statu.alarga.common.<WBR>server.actionhandler.<WBR>GetAllCrewActionHandler.<WBR>execute(<WBR>GetAllCrewActionHandler.java:<WBR>1)
>     at com.statu.alarga.common.<WBR>server.AbstractServiceImpl.<WBR>execute(AbstractServiceImpl.<WBR>java:32)
>     at sun.reflect.<WBR>NativeMethodAccessorImpl.<WBR>invoke0(Native Method)
>     at sun.reflect.<WBR>NativeMethodAccessorImpl.<WBR>invoke(<WBR>NativeMethodAccessorImpl.java:<WBR>39)
>     at sun.reflect.<WBR>DelegatingMethodAccessorImpl.<WBR>invoke(<WBR>DelegatingMethodAccessorImpl.<WBR>java:25)
>     at java.lang.reflect.Method.<WBR>invoke(Method.java:597)
>     at com.google.gwt.user.server.<WBR>rpc.RPC.<WBR>invokeAndEncodeResponse(RPC.<WBR>java:569)
>     at com.google.gwt.user.server.<WBR>rpc.RemoteServiceServlet.<WBR>processCall(<WBR>RemoteServiceServlet.java:208)
>     at com.google.gwt.user.server.<WBR>rpc.RemoteServiceServlet.<WBR>processPost(<WBR>RemoteServiceServlet.java:248)
>     at com.google.gwt.user.server.<WBR>rpc.<WBR>AbstractRemoteServiceServlet.<WBR>doPost(<WBR>AbstractRemoteServiceServlet.<WBR>java:62)
>     at javax.servlet.http.<WBR>HttpServlet.service(<WBR>HttpServlet.java:637)
>     at javax.servlet.http.<WBR>HttpServlet.service(<WBR>HttpServlet.java:717)
>     at org.mortbay.jetty.servlet.<WBR>ServletHolder.handle(<WBR>ServletHolder.java:487)
>     at org.mortbay.jetty.servlet.<WBR>ServletHandler$CachedChain.<WBR>doFilter(ServletHandler.java:<WBR>1097)
>     at com.statu.alarga.common.<WBR>server.RequestFilter.doFilter(<WBR>RequestFilter.java:24)
>     at org.mortbay.jetty.servlet.<WBR>ServletHandler$CachedChain.<WBR>doFilter(ServletHandler.java:<WBR>1088)
>     at org.mortbay.jetty.servlet.<WBR>ServletHandler.handle(<WBR>ServletHandler.java:360)
>     at org.mortbay.jetty.security.<WBR>SecurityHandler.handle(<WBR>SecurityHandler.java:216)
>     at org.mortbay.jetty.servlet.<WBR>SessionHandler.handle(<WBR>SessionHandler.java:181)
>     at org.mortbay.jetty.handler.<WBR>ContextHandler.handle(<WBR>ContextHandler.java:729)
>     at org.mortbay.jetty.webapp.<WBR>WebAppContext.handle(<WBR>WebAppContext.java:405)
>     at org.mortbay.jetty.handler.<WBR>HandlerWrapper.handle(<WBR>HandlerWrapper.java:152)
>     at org.mortbay.jetty.handler.<WBR>RequestLogHandler.handle(<WBR>RequestLogHandler.java:49)
>     at org.mortbay.jetty.handler.<WBR>HandlerWrapper.handle(<WBR>HandlerWrapper.java:152)
>     at org.mortbay.jetty.Server.<WBR>handle(Server.java:324)
>     at org.mortbay.jetty.<WBR>HttpConnection.handleRequest(<WBR>HttpConnection.java:505)
>     at org.mortbay.jetty.<WBR>HttpConnection$RequestHandler.<WBR>content(HttpConnection.java:<WBR>843)
>     at org.mortbay.jetty.HttpParser.<WBR>parseNext(HttpParser.java:647)
>     at org.mortbay.jetty.HttpParser.<WBR>parseAvailable(HttpParser.<WBR>java:211)
>     at org.mortbay.jetty.<WBR>HttpConnection.handle(<WBR>HttpConnection.java:380)
>     at org.mortbay.io.nio.<WBR>SelectChannelEndPoint.run(<WBR>SelectChannelEndPoint.java:<WBR>395)
>     at org.mortbay.thread.<WBR>QueuedThreadPool$PoolThread.<WBR>run(QueuedThreadPool.java:488)
> Caused by: java.lang.RuntimeException: java.lang.<WBR>IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [className]
>     at com.google.code.morphia.<WBR>mapping.EmbeddedMapper.<WBR>fromDBObject(EmbeddedMapper.<WBR>java:149)
>     at com.google.code.morphia.<WBR>mapping.Mapper.<WBR>readMappedField(Mapper.java:<WBR>543)
>     at com.google.code.morphia.<WBR>mapping.Mapper.fromDb(Mapper.<WBR>java:520)
>     at com.google.code.morphia.<WBR>mapping.Mapper.fromDBObject(<WBR>Mapper.java:272)
>     at com.google.code.morphia.query.<WBR>MorphiaIterator.convertItem(<WBR>MorphiaIterator.java:66)
>     at com.google.code.morphia.query.<WBR>MorphiaIterator.processItem(<WBR>MorphiaIterator.java:53)
>     at com.google.code.morphia.query.<WBR>MorphiaIterator.next(<WBR>MorphiaIterator.java:48)
>     at com.google.code.morphia.query.<WBR>QueryImpl.asList(QueryImpl.<WBR>java:258)
>     at com.statu.alarga.common.<WBR>server.dao.CrewDaoImpl.<WBR>findAllActive(CrewDaoImpl.<WBR>java:109)
>     ... 33 more
> Caused by: java.lang.<WBR>IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [className]
>     at org.bson.types.BasicBSONList._<WBR>getInt(BasicBSONList.java:161)
>     at org.bson.types.BasicBSONList._<WBR>getInt(BasicBSONList.java:152)
>     at org.bson.types.BasicBSONList.<WBR>get(BasicBSONList.java:104)
>     at com.google.code.morphia.<WBR>mapping.DefaultCreator.<WBR>getClass(DefaultCreator.java:<WBR>78)
>     at com.google.code.morphia.<WBR>mapping.DefaultCreator.<WBR>createInstance(DefaultCreator.<WBR>java:48)
>     at com.google.code.morphia.<WBR>mapping.EmbeddedMapper.<WBR>readMapOrCollectionOrEntity(<WBR>EmbeddedMapper.java:232)
>     at com.google.code.morphia.<WBR>mapping.EmbeddedMapper.<WBR>readCollection(EmbeddedMapper.<WBR>java:178)
>     at com.google.code.morphia.<WBR>mapping.EmbeddedMapper.<WBR>fromDBObject(EmbeddedMapper.<WBR>java:122)
>     ... 41 more
>
> my method is very simple
>
> @Override
>   public List&lt;Crew&gt; findAllActive() throws AlargaException {
>     try {
>
>       Query&lt;Crew&gt; query = createQuery().field(&quot;<WBR>accountStatus&quot;)
>           .equal(AccountStatus.Active);
>
>       QueryResults&lt;Crew&gt; find = dao.find(query);
>
> List&lt;Crew&gt; asList = find.asList();
>
>       // sort the result
>       // bad mongo ahhhh!!
>       Collections.sort(asList, new CrewComparator());
>
>       return asList;
>
>     } catch (Exception e) {
>         e.fillInStackTrace();
>         e.printStackTrace();
>       throw new AlargaException(getClass().<WBR>getSimpleName() + &quot;[findAllActive] - &quot; + e.toString());
>     }
>   }
>
> the generated query is
> { &quot;accountStatus&quot; : &quot;Active&quot;}
>
> which is fine, i tried it on with jmongobrowser and its successful.
>
> My crew object is like this
>
> @Entity
> public class Crew implements Serializable {
>
>   /**
>    * The key provider that provides the unique ID of a Crew.
>    */
>   public static final ProvidesKey&lt;Crew&gt; KEY_PROVIDER = new ProvidesKey&lt;Crew&gt;() {
>     public Object getKey(Crew item) {
>       return item == null ? null : <a href="http://item.id" target="_blank">item.id</a>;
>     }
>   };
>
>   @Id
>   public ObjectId id;
>
>   @Reference
>   private List&lt;Comment&gt; comments = new ArrayList&lt;Comment&gt;();

Kirk Lashley

unread,
Jul 3, 2013, 2:18:49 PM7/3/13
to mor...@googlegroups.com
I recently started to encounter this error as well. I'm curious as to your thought process to diagnose, troubleshoot and solve this problem.

--
Kirk

Justin Lee

unread,
Jul 3, 2013, 2:55:41 PM7/3/13
to mor...@googlegroups.com
If you can attach a test case (or better yet, file an issue with that test case), I can look in to it.  If not, I'll try to reconstruct one from the quoted message.

--------------------------------

name     : "Justin Lee", 
  title    : "Member of Technical Staff",
  twitter  : "@evanchooly",
  web      : "antwerkz.com",
  location : "New York, NY" }



--
You received this message because you are subscribed to the Google Groups "Morphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to morphia+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kirk Lashley

unread,
Jul 4, 2013, 12:18:33 PM7/4/13
to mor...@googlegroups.com
Thanks Justin,

I did effectively diagnose the problem on my side yesterday. The error message sent me on a wild goose chase until I was able to find the cause. If someone else has this problem I'll effectively trace my steps and also recommend to better error messages so we can find the problem. Although I'm using Jim's Morphia version, I also had the same problem with Scott's version 0.99-1.

Error caught here:

Here's my stack trace:

Error java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [className]
| Error         at com.github.jmkgreen.morphia.mapping.DefaultMapper.fromDb(DefaultMapper.java:575)
| Error         at com.github.jmkgreen.morphia.mapping.DefaultMapper.fromDBObject(DefaultMapper.java:276)
| Error         at com.github.jmkgreen.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:64)
| Error         at com.github.jmkgreen.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:51)
| Error         at com.github.jmkgreen.morphia.query.MorphiaIterator.next(MorphiaIterator.java:46)
| Error         at com.github.jmkgreen.morphia.query.QueryImpl.asList(QueryImpl.java:261)
| Error         at com.github.jmkgreen.morphia.query.QueryResults$asList.call(Unknown Source)

| Error Caused by: java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [className]
| Error         at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:161)
| Error         at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:152)
| Error         at org.bson.types.BasicBSONList.get(BasicBSONList.java:104)
| Error         at com.github.jmkgreen.morphia.mapping.DefaultCreator.getClass(DefaultCreator.java:77)
| Error         at com.github.jmkgreen.morphia.mapping.DefaultCreator.createInstance(DefaultCreator.java:47)
| Error         at com.github.jmkgreen.morphia.mapping.EmbeddedMapper.readMapOrCollectionOrEntity(EmbeddedMapper.java:234)
| Error         at com.github.jmkgreen.morphia.mapping.EmbeddedMapper.readCollection(EmbeddedMapper.java:179)
| Error         at com.github.jmkgreen.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:123)

I don't believe the problem should have ever gotten to the BasicBSONList class, as by that time it had lost all relevant information to give the user a proper error message. I ended up finding a working object and a broken object and comparing them I realized that I had inadvertently performed an UpdateOperation on an embedded collection to add a list within it to add the list instead of set the list. Of course, this created a new list inside of my list, that Morphia was not able to map properly since it expected a list of embedded entity, instead of a list of list of embedded entity. I'm not sure where the error should have been caught, but it shouldn't have been allowed to propagate all the way to BasicBSONList.

I hope this was able to help someone.

Regards,
Kirk
Reply all
Reply to author
Forward
0 new messages