在jongo中查询整个集合

时间:2013-11-21 11:45:04

标签: java jongo

我正试图从这个集合中获取所有结果,并试图打印第一个:

MongoCollection musics = JNDIManager.getJongoCollection("musics");
Iterable<MusicObject> all = musics.find().as(MusicObject.class);

MusicObject类:

public class MusicObject {
    @Id
    private final String _id; // refers to directory
    private String name;
    private String directory;

    MusicObject() {};
}

和db.musics.find()导致

{"_id": ObjectId("..."), "name": " Certain Name", "directory" : "C:\\..."}
{"_id": ObjectId("..."), "name": " Certain Name 2", "directory" : "C:\\..."}
{"_id": ObjectId("..."), "name": " Certain Name 3", "directory" : "C:\\..."}

具有完整的异常堆栈跟踪

org.jongo.marshall.MarshallingException: Unable to unmarshall result to class br.com.evans.dao.musics.MusicObject from content {"_id": ObjectId("..."), "name": " Certain Name", "directory" : "C:\\..."}
at org.jongo.marshall.jackson.JacksonEngine.unmarshall(JacksonEngine.java:45)
at org.jongo.ResultHandlerFactory$ResultUnmarshallingHandler.map(ResultHandlerFactory.java:43)
at org.jongo.MongoIterator.next(MongoIterator.java:44)
at br.com.evans.jdni.music.MusicPlayer.setMusicListFromDB(MusicPlayer.java:52)
at br.com.evans.command.repository.CommandRepository.proccesNode(CommandRepository.java:47)
at br.com.evans.behavior.nodes.core.MusicBehavior.execute(MusicBehavior.java:40)
at br.com.evans.servlets.behavior.BehaviorExecution.doPost(BehaviorExecution.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at br.com.evans.servlet.filters.SessionFilter.doFilter(SessionFilter.java:55)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.CharConversionException: Invalid UTF-32 character 0x64695f07(above 10ffff)  at char #1, byte #7)
at com.fasterxml.jackson.core.io.UTF32Reader.reportInvalid(UTF32Reader.java:155)
at com.fasterxml.jackson.core.io.UTF32Reader.read(UTF32Reader.java:109)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.loadMore(ReaderBasedJsonParser.java:122)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd(ReaderBasedJsonParser.java:1651)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:552)
at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:1293)
at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1199)
at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:862)
at org.jongo.marshall.jackson.JacksonEngine.unmarshall(JacksonEngine.java:42)
... 27 more

如何解决这个问题?我搜索了jongo文档,我可以理解我将我的MusicObject映射错误,只是不知道我应该做什么。试过@Id,long,String,@ ObjectId

编辑:此外,删除了目录列中的唯一索引。

1 个答案:

答案 0 :(得分:1)

我没有复制您描述的行为,但这可能与问题https://github.com/bguerout/jongo/issues/136

有关

您可以使用此早期版本进行测试。 此版本必须被视为未来1.0版本的快照

<dependencies>
  <dependency>
    <groupId>org.jongo</groupId>
    <artifactId>jongo</artifactId>
    <version>1.0-early-20131120-1751</version>
  </dependency>
</dependencies>
...
<repositories>
    <repository>
       <id>cloudbees-jongo-early-release</id>
        <url>http://repository-jongo.forge.cloudbees.com/release</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>