简体   繁体   中英

JPA inner join path not found and property not found

I have a JPA Typed query join issue. 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! 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.

Here is the actual java code I used:

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.

Assuming you have a XToOne relation between CubeValuesEntity and CubeConfigEntity, a property named "cubeConfig":

  • Forget the 'on' keyword - that's SQL, it's implied by the dotted expression and it's mapping
  • "could not resolve property: CubeConfigEntity" seems logical since that's the entity name, not property

So, simply try this:

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

br, Jens

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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