我有三个类,比如Vehicle作为基础类型,Car和Bike正在使用Vehicle类。
问题是我想让所有使用查询dsl的车辆和车辆的条件
车辆类
@Entity
@Table(name="vehicles")
@Inheritance(strategy=InheritanceType.JOINED)
public class Vehicle {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", length = 30)
private Integer id;
private String brand;
private String color;
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
汽车类
@Entity
@Table(name="cars")
public class Car extends Vehicle {
private int totalDoor;
private int numeberofSeats;
public int getTotalDoor() {
return totalDoor;
}
public void setTotalDoor(int totalDoor) {
this.totalDoor = totalDoor;
}
public int getNumeberofSeats() {
return numeberofSeats;
}
public void setNumeberofSeats(int numeberofSeats) {
this.numeberofSeats = numeberofSeats;
}
}
自行车课程
@Entity
@Table(name="bikes")
public class Bike extends Vehicle {
private int numerberOfTiers;
public int getNumerberOfTiers() {
return numerberOfTiers;
}
public void setNumerberOfTiers(int numerberOfTiers) {
this.numerberOfTiers = numerberOfTiers;
}
}
查询所有车辆,但在哪里指定汽车和自行车预测?
List<Vehicle> vehicles = new JPAQuery(manager)
.from(vehicle)
.distinct()
.list(Projections.bean(Vehicle.class , vehicle.brand));
答案 0 :(得分:1)
您可以在单独的查询中填充特定的子类型,但不能在一个查询中填充。因此,您可以对子类型进行特定的单独查询,也可以对结果进行后处理。