【发布时间】:2023-04-07 09:10:02
【问题描述】:
我正在使用 Spring 数据 (jpa-repository),并且我有以下实体:
public class City{
....
private Street street;
....
}
public class Street{
...
private List<Building> buildings;
...
}
public class Building{
...
private List<Flat> flats;
....
}
public class Flat{
...
private boolean lightsOn;
...
}
我想创建一个查询来获取所有(不同的)城市,这些城市至少有一个带电灯的公寓。
我试过这个查询:
@Query("select distinct c from Cities c where c.street.buildings.flats.lightsOn = true")
但收到此错误消息:
The state field path 'c.street.buildings.flats.lightsOn' cannot be resolved to a valid type.
我该怎么做?
【问题讨论】:
-
我不熟悉 JPQL。建筑物(和公寓)是
Lists -
@Michael - 我确定是这样 - 我只是不知道正确的查询是什么(我确定有办法)
-
@Gimby - 感谢您注意到错字(更改了我的问题) - 仍然收到此错误
-
@Gimby - 再次感谢
-
select distinct c from City c JOIN c.street s JOIN s.buildings b JOIN b.flats f where f.lightsOn = true。但是看任何 JPQL 教程都会告诉你如何加入!
标签: java sql jpa spring-data jpql