Mongodb &引用;“十六进制表示法无效”;用于spring mongo数据存储库接口

Mongodb &引用;“十六进制表示法无效”;用于spring mongo数据存储库接口,mongodb,spring-data,spring-data-mongodb,Mongodb,Spring Data,Spring Data Mongodb,我有一个存储库界面,如下所示: public interface ExcursionAttendeeRepository extends MongoRepository<ExcursionAttendee, String> { ExcursionAttendee findByWorkflowItemId(String workflowItemId); @Query("{ 'excursionEvent._id' : { '$oid' : ?0 } }")

我有一个存储库界面,如下所示:

public interface ExcursionAttendeeRepository extends MongoRepository<ExcursionAttendee, String> {

    ExcursionAttendee findByWorkflowItemId(String workflowItemId);

    @Query("{ 'excursionEvent._id' : { '$oid' : ?0 } }")
    List<ExcursionAttendee> findByExcursionId(String excursionId);

    @Query("{ 'student._id' : {'$oid' : ?0} , 'excursionEvent._id' : { '$oid' : ?1 } }")
    ExcursionAttendee findByStudentIdAndEventId(String studentId, String excursionId);

    @Query("{ 'student._id' : { '$oid' : ?0 } }")
    List<ExcursionAttendee> findByStudentId(String studentId);
}

理想情况下,当尝试使用无效字符串初始化
ObjectId
时,应该抛出此异常。[ ]. 我想知道如何初始化类,以便在创建bean时抛出异常。关于这个问题有什么建议吗?

我遇到了同样的问题,下面的方法应该有效

@Query("{ 'student' : { '$id': ?0 } }")
List<ExcursionAttendee> findByStudentId(String studentId);
@Query(“{'student':{'id':?0}”)
列出findByStudentId(字符串studentId);
如果它是一个DBRef,它应该是这样的(这是我在同一个问题之后使用的,我有一个DBRef)

@Query(“{'student':{$ref':'user','$id':?0}”)
列出findByStudentId(字符串studentId);
对于DBRef,这也应该起作用

List<ExcursionAttendee> findByStudentId(String studentId);
List findByStudentId(字符串studentId);
我从中找到了答案


如果遵循,则无需指定@Query。

查询应与

@Query("{ 'student._id' : ?0} , 'excursionEvent._id' : ?1 } }")
参考:

List<ExcursionAttendee> findByStudentId(String studentId);
 @Query("{ 'student._id' : {'$oid' : ?0} , 'excursionEvent._id' : { '$oid' : ?1 } }")
ExcursionAttendee findByStudentIdAndEventId(String studentId, String excursionId);
@Query("{ 'student._id' : ?0} , 'excursionEvent._id' : ?1 } }")