Spring Data (mongoDB),存储库上的 findBy 代理方法不适用于空值

发布于 2024-11-16 10:26:49 字数 782 浏览 9 评论 0原文

我在 MongoRepository 扩展程序类中有一个代理方法,如下所示:

public interface InvitationRepository extends MongoRepository<Foo, String>
{
    public Foo findByUserIdAndDestinationMail( String userId, String destinationMail );
}

当我尝试通过调用:

Foo foo = invitationRepository.findByUserIdAndDestinationMail( userId, null );

MappingMongoConverter 在数据库中查找没有任何 destinationMailFoo 实例时> 抛出一个NullPointerException

我可以使用任何代理方法找到具有空值的实例吗?

如果我需要在自定义实现中创建方法,如何使用 mongoTemplate 来完成此操作?有这样的事吗?

mongoTemplate.findOne( new Query( 
    Criteria.where( "userId" ).is( userId ).and( "destinationMail" ).is(... )),
    entityClass );

非常感谢。

I have a proxied method in a MongoRepository extender class like this:

public interface InvitationRepository extends MongoRepository<Foo, String>
{
    public Foo findByUserIdAndDestinationMail( String userId, String destinationMail );
}

When I try to find a Foo instance in DB without any destinationMail by calling:

Foo foo = invitationRepository.findByUserIdAndDestinationMail( userId, null );

MappingMongoConverter throws a NullPointerException.

¿Can I find instances with null values with any proxied method?

If I need to create the method in a custom implementation ¿how can I do this with mongoTemplate? ¿Is there somthing like this?

mongoTemplate.findOne( new Query( 
    Criteria.where( "userId" ).is( userId ).and( "destinationMail" ).is(... )),
    entityClass );

Thank you very much.

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

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

发布评论

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

评论(1

葮薆情 2024-11-23 10:26:49

目前的1.0.1.RELEASE版本中似乎没有出现这个问题。因此,如果您遇到此问题,请升级到此版本。

The problem doesn't seem to appear in the current 1.0.1.RELEASE version. Thus if you face this issue, please upgrade to this version.

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