@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 запрос, где
@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