Request in the @DBRef field

Usage: Spring 3.1.0.RELEASE, Spring Data MongoDB 1.0.0.RELEASE

I have a document class defined as follows:

@Document public class MyDoc { @Indexed @DBRef private User owner; ... 

I am trying to select all MyDoc instances for a specific user using the definition of this repository:

 public interface MyDocRepository extends CrudRepository<MyDoc, String> { List<MyDoc> findByOwner(User owner); } 

Unfortunately, this does not find anything: the code works fine, without exception, but, alas, nothing was found.

So what is the right way to select documents in the DBRef-ed field?

NB . I saw this question , but my usage example is simpler because I don't want to filter by the property of the DBRef-ed object.

Refresh . While the repositories do not support DBRef search, I decided to go with a simple workaround: use MongoTemplate to generate a query that uses com.mongodb.DBRef as a field criterion. It works great.

+4
source share
1 answer

It looks like this is not supported by Spring Data:

I think the problem has been resolved due to the proxy server being used, but I haven't looked at the code yet.

+1
source

Source: https://habr.com/ru/post/1395713/


All Articles