@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
添加回答
举报
0/150
提交
取消