简体   繁体   English

找不到JPA内部联接路径和找不到属性

[英]JPA inner join path not found and property not found

I have a JPA Typed query join issue. 我有一个JPA类型查询联接问题。 When I use the following code 当我使用以下代码

    SELECT cve from CubeValuesEntity cve inner join CubeConfigEntity cce
    on cve.cubeConfigId=cce.cubeConfigId 

I get a QuerySyntaxException: Path expected for join! 我得到一个QuerySyntaxException:预期加入的路径! which I believe the fix to that error is the following 我认为该错误的解决方法如下

  SELECT cve from CubeValuesEntity cve inner join cve.CubeConfigEntity cce 
  on cve.cubeConfigId=cce.cubeConfigId

However I now get QueryException: could not resolve property: CubeConfigEntity which makes no sense at all. 但是我现在得到QueryException:无法解析属性:CubeConfigEntity这根本没有任何意义。

Here is the actual java code I used: 这是我使用的实际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();

Here are my entities 这是我的实体

    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;

Thanks for your help. 谢谢你的帮助。

I belive you're mixing JQL and SQL here. 我相信您在这里混用了JQL和SQL。

Assuming you have a XToOne relation between CubeValuesEntity and CubeConfigEntity, a property named "cubeConfig": 假设您在CubeValuesEntity和CubeConfigEntity之间有一个XToOne关系,这是一个名为“ cubeConfig”的属性:

  • Forget the 'on' keyword - that's SQL, it's implied by the dotted expression and it's mapping 忘记“ on”关键字-这是SQL,由点分表达式和映射表示
  • "could not resolve property: CubeConfigEntity" seems logical since that's the entity name, not property “无法解析属性:CubeConfigEntity”似乎是合理的,因为那是实体名称,而不是属性

So, simply try this: 因此,只需尝试以下操作:

"SELECT cv from CubeValuesEntity cv inner join cv.cubeConfig cc where..."

br, Jens br,詹斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM