4

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

I have a document class defined like this:

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

I'm trying to select all MyDoc instances for a particular user with this repository definition:

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

Unfortunately this doesn't find anything: the code runs fine, no exception, but alas nothing is found.

So what is the proper way to select documents by a DBRef-ed field?

NB. I have seen this question but my use case is simpler as I don't want to filter by a property of the DBRef-ed entity.

Update: Until repositories support finding by DBRef, I've decided to go with a simple workaround: use the MongoTemplate to form a query that uses a com.mongodb.DBRef as a field criteria. Works fine.

Community
  • 1
  • 1
David Dossot
  • 33,403
  • 4
  • 38
  • 72

1 Answers1

1

It looks like this not supported by Spring Data yet:

I think the problem resolves around the fact that a proxy is used, but I haven't looked at the code yet.

Scott Hernandez
  • 7,452
  • 2
  • 34
  • 25