On a Spring project I’m using Spring Data MongoDB, and have 2 classes:
public class ClassA
{
@Id
private String id;
private String description
@DBRef
private ClassB classBId;
// Getters and Setters
}
public class ClassB
{
@Id
private String id;
private String description
// Getters and Setters
}
Being so I have 2 collections, classA and classB and populated them with several instances.
The classA instances are being stored like:
{ “_id” : { “$oid” : “5086b371004d7c4bfff0a142”} , “_class” :
“com.spring.custom.ClassA”, “description” : “Description A” ,
“classBId” : { “$ref” : “classB” , “$id” : { “$oid” :
“50866d45004d84852b16a8b8”}}}
My question is, how do I make a query that will return all classA objects that reference to classB instance with id
50866d45004d84852b16a8b8?
I’ve tried like this but with no sucess:
ClassB cb = new ClassB(); cb.setId("50866d45004d84852b16a8b8");
Criteria criteria = Criteria.where("classBId").is(classBObject);
Query query = new Query(); query.addCriteria(criteria);
Found a way to do what I need…
Unfortunatelly it isn’t the way I expected but it’s a solution nevertheless…
I’ve even tried updating my Spring Data MongoDB API to 1.0.4 RELEASE instead of 1.0.2 RELEASE in hope that I would be able to get the same result like:
But I just kept getting the following error:
java.lang.RuntimeException: json can’t serialize type : class ClassB…