java - 我可以将 hibernate/jpa 查询的结果映射到不是实体的类吗?
问题描述
我正在尝试使用 Springboot,我有几个具有几个非常相似的属性的实体,例如:实体“汽车”具有模型和价格属性,“摩托车”模型也是如此。我想使用一个类来定义那些常见的属性,即带有属性模型和价格的“车辆”类。
换句话说:
Car Motorcicle Vehicle
price price price
model model model
year year
color color
fuel_type fuel_type
... 30 more properites ...30 more properties
我想使用车辆来映射 Car 和 Motorcycle 表之间的 SQL 联合的搜索结果。
public interface ImovelRepositorio extends JpaRepository<Vehicle, Long> {
@Query(value = "here select query with union between car and motorcycle", nativeQuery = true)
List<Vehicle> searchVehicle();
}
这里的 Vehicle 类是一个没有任何注释的普通类。我收到错误消息说 Vehicle 不是托管类型。当然我的存储库没有意义,我预计会出现这个错误。但是我怎样才能实现我想要的呢?
当我执行联合时,我没有得到模型列表,而是得到一个或多个模型的列表。我想创建一个类来“组合”搜索结果。
解决方案
FluentJPA 有针对这种情况的解决方案。
推荐阅读
- c# - 如何对 DataGrid 的最后一列中的值求和
- css - 如何在prime ng面板菜单中设置活动菜单?
- python - 在 seaborn 气泡图中添加颜色条
- vsto - Outlook 邮件:使用 vsto 更改邮件主题颜色的选项
- python - 调用时的函数执行问题,python
- java - 如何在 Rxjava 中的列表更改时通知观察者
- amazon-web-services - 在构建项目“Build container dead”时
- c++ - 即使直接分配给非 NULL 指针,指针也为 NULL
- javascript - 更新一个对象,如果不存在则创建它
- php - $this->request->getPost('email') 在执行 axios POST 请求时没有给出任何值