重新初始化播放吗啡后 findAll 失败

发布于 2024-12-26 01:01:11 字数 2623 浏览 1 评论 0原文

我有以下类,它在戏剧中使用吗啡持久保存到 mongodb 中!应用。该类驻留在一个模块中,该模块是另一个游戏的依赖项!应用。

它的配置是从文件中读取的,并在初始加载时保存到数据库中(如果它尚未在数据库中),然后后续请求使用数据库版本。

@Entity
public class Page extends Model {

    @Id
    public Long navigationId;

    // etc ...
}

初始加载和后续查询访问工作正常,我可以在 mongo 中看到该页面:

> db.Page.find({_id:20000})
{ "_id" : NumberLong(20000), "className" : "models.Page" etc }

但是如果我重新启动游戏!或进行代码更改,导致 Morphia 重新初始化 (MorphiaPlugin-1.2.4>初始化出现在日志中)我得到以下堆栈跟踪:

Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
    at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:487)
    at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:267)
    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:255)
    at play.modules.morphia.Model$MorphiaQuery.asList(Model.java:1067)
    at models.Page.findAll(Page.java)
    at plugins.PageConfigLoadPlugin.loadPersistedPages(PageConfigLoadPlugin.java:62)
    at plugins.PageConfigLoadPlugin.onApplicationStart(PageConfigLoadPlugin.java:51)
    at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:425)
    at play.Play.start(Play.java:495)
    ... 3 more
Caused by: java.lang.RuntimeException: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
    at com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:27)
    at com.google.code.morphia.mapping.Mapper.readMappedField(Mapper.java:501)
    at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:484)
    ... 14 more
Caused by: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
    at com.google.code.morphia.converters.DefaultConverters.fromDBObject(DefaultConverters.java:133)
    at com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:25)
    ... 16 more

如果我使用命令行从mongodb中删除集合,我可以再次从我的页面成功加载和查询页面对象玩! Web 应用程序

> db.Page.drop()
true

正如我所提到的,此类位于模块中。此问题仅发生在该模块依赖的一个应用程序中。另一个演示应用程序运行良好。

有什么建议吗?

I have the following class which is persisted into a mongodb using morphia in a play! application. The class resides in a module which is a dependency of another play! application.

Its configuration is read from a file and persisted into the db on initial load (if its not already in the db) and then subsequent requests use the db version.

@Entity
public class Page extends Model {

    @Id
    public Long navigationId;

    // etc ...
}

The initial load and subsequent query access works ok and i can see the page in mongo:

> db.Page.find({_id:20000})
{ "_id" : NumberLong(20000), "className" : "models.Page" etc }

However if i restart play! or make a code change that results in Morphia being reinitialised
(MorphiaPlugin-1.2.4> initialized appears in the logs) i get the following stack trace:

Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
    at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:487)
    at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:267)
    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:255)
    at play.modules.morphia.Model$MorphiaQuery.asList(Model.java:1067)
    at models.Page.findAll(Page.java)
    at plugins.PageConfigLoadPlugin.loadPersistedPages(PageConfigLoadPlugin.java:62)
    at plugins.PageConfigLoadPlugin.onApplicationStart(PageConfigLoadPlugin.java:51)
    at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:425)
    at play.Play.start(Play.java:495)
    ... 3 more
Caused by: java.lang.RuntimeException: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
    at com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:27)
    at com.google.code.morphia.mapping.Mapper.readMappedField(Mapper.java:501)
    at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:484)
    ... 14 more
Caused by: com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000
    at com.google.code.morphia.converters.DefaultConverters.fromDBObject(DefaultConverters.java:133)
    at com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:25)
    ... 16 more

If i drop the Collection from mongodb using the command line i can again load and query the Page obejct successfully from my play! web application

> db.Page.drop()
true

As I mentioned, this class is in a module. This problem only happens in one application that the module is a dependency of. The other demo application works fine.

any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴意少年 2025-01-02 01:01:11

依赖模块是否有另一个替代的页面声明或
模型类?

从堆栈跟踪的顶部(“com.google.code.morphia.mapping.MappingException:模型的转换器(LongConverter)的错误设置值到20000”),看起来之间存在类型不匹配
存储和检索数值的方式。例如,在Java中,
将某些内容存储为 Double 然后错误地尝试的情况并不少见
将其检索为整数或长整型。那么,您能否验证一下
依赖模块中navigationId的声明与之前的相同
你在这里展示过吗?他们应该共享定义,但有可能
一个替补。

另一件要检查的事情是您的代码是否将 Long 放入您的
DBObject 而不是浮点数。例如,如果您通过 shell 插入它,
您需要使用包装器之一,例如

db.Page.save({_id:NumberLong(20000)});

否则,这也会导致检索时不匹配;默认情况下
JavaScript 中的数字是双精度数。

Does the dependent module have another alternate declaration of the Page or
Model classes?

From the top of the stack trace, ("com.google.code.morphia.mapping.MappingException: Error setting value from converter (LongConverter) for models.Page.navigationId to 20000"), it looks like there's a type mismatch between
the way a numeric value is being stored and retrieved. For example, in Java,
it is not uncommon to store something as a Double and then mistakenly try
to retrieve it as an Integer or a Long. So, can you verify that the
declaration of navigationId in the dependent module is the same as the one
you've shown here? They should share the definition, but its possible there's
an alternate.

Another thing to check is that your code is putting a Long into your
DBObject and not a float. For example, if you're inserting it via the shell,
you'll need to use one of the wrappers, e.g.

db.Page.save({_id:NumberLong(20000)});

Otherwise, this will also cause a mismatch when you retrieve it; by default
numbers in JavaScript are doubles.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文