-
Aug 15th, 2011, 05:19 PM
#1
How to query documents with @DBRef using repositories
I have two collections: Address and Person. Person refers Address class.
@Document
public class Address {
@Id
private ObjectId id;
}
@Document
public class Person {
@Id
private ObjectId id;
@DBRef
private Address add;
//getters and setters
}
Previously, I used MongoTemplate for querying and I was able to query using $id reference. Now, after moving to M3 I am trying to switch my data layer to use spring data's repositories. Can you please advice on how the @DbRef will work with repos? For example, I want to do the following:
public interface AddressRepository extends MongoRepository<Person, ObjectId> {
}
public interface PersonRepository extends MongoRepository<Address, ObjectId> {
List<Person> findByAddress(Address a);
}
Thanks in advance.
Last edited by aachpach; Aug 15th, 2011 at 06:09 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules