我有一个City聚合,有一个PointOfInterest实体列表。后一个实体在逻辑上位于 City 聚合中,原因在此不作解释。除了聚合根 City 之外,没有任何实体拥有指向 PointOfInterest 的链接。
但是,我们有一个 PointOfInterest 网页,可从 City 页面浏览,该网页(主要出于 SEO 原因)id在其 URL 中仅包含 PointOfInterest。
因此,从控制器中,直接向 CityRepository 查询 PointOfInterest 会很方便,例如CityRepository.findPointOfInterestById().
另一种选择是查询CityRepository.findCityByPointOfInterestId(), then City.findPointOfInterestById(),在这种情况下看起来有点麻烦。
第一种方法有什么问题吗?