城市实体具有SynopticData列表。
public class City {
@Id
@GeneratedValue
private Long id;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "city_id")
private List<SynopticData> synopticDataList;
}
是否可以使用特定SynopticDates列表获取City? 我有这样的查询:
@Repository
public interface CityRepository extends JpaRepository<City,Long> {
@Query(value = "SELECT * FROM city c left join synoptic_data s on c.id=s.city_id
where s.local_date_time=(select s.local_date_time from synoptic_data s where s.city_id=c.id order by local_date_time desc limit 1) and c.name=:cityName", nativeQuery = true)
public City findCity(@Param("cityName") String name);
}
在MySql中它可以正常工作,但是在Java中,休眠状态添加了自己的查询,结果我得到了包含所有SynopticData列表的城市。
是否有可能得到该结果?有什么可能?