为了账号安全,请及时绑定邮箱和手机立即绑定

使用集合加载 DTO

使用集合加载 DTO

慕码人2483693 2021-08-25 16:46:26
@Entity@Table(name = "person")public class Consignment implements Serializable {    @Id    @GeneratedValue(strategy = GenerationType.AUTO)    private Long id;    @Column(name = "person_id")    private String personId;    @Column(name = "person_name")    private String personName;    @OneToMany(fetch = FetchType.EAGER, mappedBy = "person")    @Column(name = "cars_owned")    private Set<Cars> casrsowned = new HashSet<>();}@Entity@Table(name = "cars")public class Cars implements Serializable {    @Id    @GeneratedValue(strategy = GenerationType.AUTO)    private Long id;   @Column(name = "cars_id")    private String carsId;   @ManyToOne    @JoinColumn(name = "person")    private Person person;    @OneToOne    private CarsDetail  carsDetail;}@Entity@Table(name = "carsDetail")public class CarsDetail implements Serializable {    @Id    @GeneratedValue(strategy = GenerationType.AUTO)    private Long id;    @Column(name = "brand")    private String brand;    @Column(name = "color")    private String color;    @Column(name = "model")    private String model;}class CarModelDTO {    String personName;    List<String> models;}在上面的关系中,想要返回CarModelDTO JPA 查询 where,@Query("Select CarModelDTO(p.personName, p.casrsowned.carsDetail.model) from Person as p where p`enter code here`.id = :id"))public CarModelDTO getCarmodelOwnedByAperson(@Param("id") Long id);我尝试了多种方法,但它给出了 org.hibernate.QueryException: illegal attempt to dereference collection
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 219 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信