我有一个JPA类型查询连接问题。当我使用以下代码时
SELECT cve from CubeValuesEntity cve inner join CubeConfigEntity cce
on cve.cubeConfigId=cce.cubeConfigId
我得到一个QuerySyntaxException:期望加入的路径!我认为对该错误的修复是以下
SELECT cve from CubeValuesEntity cve inner join cve.CubeConfigEntity cce
on cve.cubeConfigId=cce.cubeConfigId
但是我现在得到QueryException:无法解析属性:CubeConfigEntity 这完全没有意义。
这是我使用的实际java代码:
TypedQuery<CubeValuesEntity> query = em.createQuery(
"SELECT cve from CubeValuesEntity cve inner join cve.CubeConfigEntity cce on cve.cubeConfigId=cce.cubeConfigId where " + "cce.cubeType = :cubeType
and cce.name = :name and cve.axisType = :axisType", CubeValuesEntity.class)
.setParameter("cubeType", cubeType).setParameter("name", name).setParameter("axisType", axisType);
return query.getResultList();
这是我的实体
public class CubeValuesEntity extends AbstractDomainObject {
private static final long serialVersionUID = 1L;
private int cubeValueId;
private int cubeConfigId;
private String axisType;
private int axisNumber;
private String axisLabel;
private BigDecimal axisFactor;
public class CubeConfigEntity extends AbstractDomainObject {
private int cubeConfigId;
private String cubeType;
private String name;
private String yAxisName;
private Integer yAxisCubeSize;
private String xAxisName;
private Integer xAxisCubeSize;
private String reductionType;
private BigDecimal midLowRange;
private BigDecimal midHighRange;
感谢您的帮助。
答案 0 :(得分:1)
我相信你在这里混合使用JQL和SQL。
假设您在CubeValuesEntity和CubeConfigEntity之间存在XToOne关系,则名为“cubeConfig”的属性:
所以,试试这个:
"SELECT cv from CubeValuesEntity cv inner join cv.cubeConfig cc where..."
BR, 延