У меня есть класс продавца с вложенным dbref адреса. Я хотел бы выбрать розничных продавцов на основе города, который является частью класса Address. Но я получаю ошибку ниже.
org.springframework.data.mapping.model.MappingException: недопустимая ссылка на путь address.city! На ассоциации можно указывать только напрямую или через их свойство id!
Не могли бы вы сообщить мне, что не так и как это исправить?
Код приведен ниже
@Document(collection="retailer")
@TypeAlias("retailer")
public class Retailer extends CommonDomainAttributes implements Serializable {
public Retailer() {
// TODO Auto-generated constructor stub
}
@DBRef
private List<Product> products;
private String shopName;
@DBRef
private Address address;
}
@Document(collection="address")
@TypeAlias("address")
public class Address extends CommonDomainAttributes implements Serializable {
/**
*
*/
private static final long serialVersionUID = 8820483439856446454L;
private String addrLine1;
private String addrLine2;
private String locality;
private String city;
private String state;
private String country;
}
Я использую следующий запрос для получения данных
@Override
public List<Retailer> findRetailersByProductNameAndCity(String productName,
String city) {
Query query = Query.query(Criteria.where/*("product.productName").is(productName).and*/("address.city").is(city));
//BasicQuery basicQuery = new BasicQuery("{ product.productName : { $eq : '"+productName+"' }, address.city : { $eq : '"+city+"' }}");
//System.out.println(basicQuery.toString());
//query.fields().include("user");
//query.fields().include("address");
List<Retailer> retailers = mongoTemplate.find(query, Retailer.class);
return retailers;
}
Данные
db.retailer.find().pretty();
{
"_id" : ObjectId("55eb14e077c8f563fb2c11ab"),
"_class" : "retailer",
"createDate" : ISODate("2015-09-05T16:14:24.489Z"),
"lastModifiedDate" : ISODate("2015-09-05T16:14:24.489Z"),
"createdBy" : "UnAuntenticatedUser",
"lastModifiedBy" : "UnAuntenticatedUser",
"user" : DBRef("IdeaRealtyUser", ObjectId("55eb14e077c8f563fb2c11aa")),
"products" : [
DBRef("product", ObjectId("55eb14e077c8f563fb2c1193")),
DBRef("product", ObjectId("55eb14e077c8f563fb2c1194")),
DBRef("product", ObjectId("55eb14e077c8f563fb2c119a"))
],
"address" : DBRef("address", ObjectId("55eb14e0a1fd2e78e05053c2"))
}
{
"_id" : ObjectId("55eb14e077c8f563fb2c11ad"),
"_class" : "retailer",
"createDate" : ISODate("2015-09-05T16:14:24.561Z"),
"lastModifiedDate" : ISODate("2015-09-05T16:14:24.561Z"),
"createdBy" : "UnAuntenticatedUser",
"lastModifiedBy" : "UnAuntenticatedUser",
"user" : DBRef("IdeaRealtyUser", ObjectId("55eb14e077c8f563fb2c11ac")),
"products" : [
DBRef("product", ObjectId("55eb14e077c8f563fb2c1193")),
DBRef("product", ObjectId("55eb14e077c8f563fb2c1194")),
DBRef("product", ObjectId("55eb14e077c8f563fb2c119b")),
DBRef("product", ObjectId("55eb14e077c8f563fb2c119f")),
DBRef("product", ObjectId("55eb14e077c8f563fb2c11a0"))
],
"address" : DBRef("address", ObjectId("55eb14e0a1fd2e78e05053c1"))
}