Подтвердить что ты не робот

"недопустимое шестнадцатеричное представление" для spring интерфейса репозитория данных mongo

У меня есть интерфейс репозитория следующим образом:

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);
}

Пока Bean создание spring вызывает следующее исключение.

Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0.1':
  Cannot create inner bean '(inner bean)#5172829b' of type [org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter] while setting bean property 'messageListener';
  nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5172829b':
    Cannot resolve reference to bean 'productDetailsEventConsumer' while setting bean property 'delegate';
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productDetailsEventConsumer': Injection of autowired dependencies failed;
    nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.cinglevue.veip.service.excursion.ExcursionAttendeeService com.cinglevue.veip.service.erp.impl.ProductDetailsEventConsumer.excursionAttendeeService;
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'excursionAttendeeServiceImpl': Injection of autowired dependencies failed;
    nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.cinglevue.veip.repository.excursion.ExcursionAttendeeRepository com.cinglevue.veip.service.excursion.impl.ExcursionAttendeeServiceImpl.excursionAttendeeRepository;
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'excursionAttendeeRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: invalid hexadecimal representation of an ObjectId: [_param_0]

В идеале эти исключения должны возникать при попытке инициализировать ObjectId с недопустимой строкой. [код]. Мне интересно, как класс инициализируется, чтобы исключение было выбрано при создании Bean. Любые советы по этому поводу?

4b9b3361

Ответ 1

Я столкнулся с тем же вопросом, и следующее должно работать.

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

Если это DBRef, он должен быть таким: (Это то, что я использовал после этой же проблемы, у меня есть DBRef в моем случае)

@Query("{ 'student': {'$ref': 'user', '$id': ?0} }")
List<ExcursionAttendee> findByStudentId(String studentId);

Для DBRef это тоже должно работать,

List<ExcursionAttendee> findByStudentId(String studentId);

Я нашел ответ здесь.