2

当我将 DBRef 与 java.util.map 结合使用时,“计数”和“查找”查询的名称是什么?

在我的示例中,countByFoos-Method 总是返回 0 而不是 1。

我如何通过给定的 FooDao 找到和计算 BarDaos?

public class FooDao {

   @Id
   private String id;

   private String key; 

   ...
}

public class BarDao {

   @Id
   private String id;

   @DBRef
   private Map<String, FooDao> foos;

   ...
}

public interface FooRepository extends MongoRepository<FooDao, String> {
   ...
}

public interface BarRepository extends MongoRepository<BarDao, String> {

   long countByFoos(FooDao fooDao);

   ...
}

public void doSomthing() {
   FooDao foo = new FooDao("fooId1", "key1");
   fooRepository.save(foo);

   BarDao bar = new BarDao("barId1");
   bar.addFoo(foo.getKey(), foo);
   barRepository.save(bar);

   int count = barRepository.countByFoos(foo);
}
4

0 回答 0