我有一个包含多个映射超类的类
@EqualsAndHashCode(callSuper = true)
@Entity(name = "Supported_cars_usage")
@Data
@NoArgsConstructor
public class SupportedCarUsage extends SupportedUsageBase {
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "supported_car_id")
private SupportedCar supportedCar;
}
@MappedSuperclass
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class SupportedUsageBase extends BaseEntity {
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")
User user;
boolean allowed;
}
我正在尝试按某些嵌套字段进行选择、搜索和分组。一开始我发现我可以参考嵌套字段。
我尝试了类似的变化
Query query = em.createQuery("select supportedCar, allowed from Supported_cars_usage");
Query query = em.createQuery("select supportedCar, super.allowed from Supported_cars_usage");
Query query = em.createQuery("select supportedCar, SupportedUsageBase.allowed from Supported_cars_usage");
但因各种错误而失败。这些语法是指映射超类中的字段吗?
数据库本身是正常创建的。
Getter 存在并自动创建Lombok
(参见@Data
注释)。
我不希望使用本机查询。