[英]Spring Data JPA: find nested object
I have a LOCATION entity and it contains COUNTRY, STATE and CITY. 我有一个LOCATION实体,它包含COUNTRY,STATE和CITY。 And I have a LocationRepository interface defined as:
我有一个LocationRepository接口定义为:
public interface SpringDataLocationRepository extends LocationRepository,
Repository<Location, Integer> {
}
I want to find all the state by country. 我想按国家找到所有州。 I can follow the method name standard to query everything for LOCATION entity.
我可以遵循方法名称标准来查询LOCATION实体的所有内容。 If I want List, do I need to create StateRepository interface and query everything about STATE in there?
如果我想要列表,是否需要创建StateRepository接口并在那里查询有关STATE的所有信息? If I can just get it from LocationRepository, what's the method looks like?
如果我可以从LocationRepository中获取它,那么方法是什么样的? I assume it will look something like below (of course it doesn't work).
我认为它看起来像下面的样子(当然不起作用)。
List findStateByCountryCountryId(Integer id) throws DataAccessException; 列表findStateByCountryCountryId(Integer id)抛出DataAccessException;
Below method should work: 下面的方法应该工作:
List<Location> findByCountryId(Integer id)
Then you can get state from the Location
objects in the list. 然后,您可以从列表中的
Location
对象获取状态。
PS: Of course, this is not tested/executed by me. PS:当然,这不是我测试/执行的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.