【发布时间】:2022-01-14 11:01:25
【问题描述】:
我遇到了嵌套投影的问题。 (内部投影)
根实体:
@Entity(name = "AAA")
@NoArgsConstructor
@AllArgsConstructor
@Data
public class AAA{
@Id
private Long id;
@OneToOne
private BBB bbb;
}
BBB 看起来像这样:
@Entity(name = "BBB")
@NoArgsConstructor
@AllArgsConstructor
@Data
public class BBB{
@Id
private Long id;
@Column(name = "name")
private String name;
预测
public record AAAProjection(
Long id,
BBBProjection bbb
) {
}
public record BBBProjection(
Long id,
String name
) {
}
当我尝试使用这些投影进行查询时,会引发异常:
org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class AAAProjection
在 Spring Boot Data JPA 的投影中有什么方法可以使用嵌套投影?
【问题讨论】:
标签: java spring-boot hibernate spring-data-jpa spring-projections