I use the version of Spring-Data-MongoDB is 1.2, codes flow:
I have look up the document, up two ways is right, but the query result is empty, the database have data, so how to solve the question? thanks!
Code:
@Document
public class Folder {
@Id
private String id;
@DBRef
private Email email;
private String name;
private String path;
Getter and Setter Method 。。。
}
Code:
@Document
public class Email {
@Id
private String id;
@DBRef
private User user;
private String address;
Getter and Setter Method 。。。
}
Code:
public List<Folder> findByEmailAddress(String address) {
Query query = new Query();
query.addCriteria(Criteria.where("email.address").is(address));
return mongoTemplate.find(query, Folder.class);
}
or
@Transactional
public interface FolderRepository extends MongoRepository<Folder, String>{
List<Folder> findByEmailAddress(String address);
}