0

Is it possible to search based on some param value of a DBRef object in spring data.

eg. say we have two objects, Car, and Company as shown

Class Car {

   @Id
   String id;
   String model;
   @DBRef
   Company company;
}

Class Company {

   @Id
   String id;
   String name;
}

Can I write a query to fetch all car's of Hyundai company like this,

Query queryForCars = new Query(Criteria.where("company.name").is("Hyundai")), Car.class)

It works fine for non referenced objects, but for referenced object it's working in my case.

Thanks for your help.

shailesh
  • 763
  • 2
  • 9
  • 23

1 Answers1

1

For referenced objects this is how your query should look like:

Query queryForCars = new Query(Criteria.where("company.$name").is("Hyundai")), Car.class)

vmr
  • 1,895
  • 13
  • 24