Jpa 带有条件API的Case语句和NVL-IllegalArgumentException:属性[SingularAttributeImpmappings.DirectToFieldMapping

Jpa 带有条件API的Case语句和NVL-IllegalArgumentException:属性[SingularAttributeImpmappings.DirectToFieldMapping,jpa,eclipselink,jpa-2.0,criteria,criteria-api,Jpa,Eclipselink,Jpa 2.0,Criteria,Criteria Api,我能够使用JPA标准生成器构建标准 Java代码片段 cq.multiselect(root.get(ProductCatalogue_.userId),root.get(ProductCatalogue_.productList)); Join<ProductCatalogue, ProductList> joinList = root.join(ProductCatalogue_.productList, JoinType.LEFT); Join<Prod

我能够使用JPA标准生成器构建标准

Java代码片段

cq.multiselect(root.get(ProductCatalogue_.userId),root.get(ProductCatalogue_.productList));

    Join<ProductCatalogue, ProductList> joinList = root.join(ProductCatalogue_.productList, JoinType.LEFT);
    Join<ProductCatalogue, ProductEmp> joinEmp = root.join(ProductCatalogue_.productEmp, JoinType.LEFT);
例外情况

java.lang.IllegalArgumentException:托管类型中的属性[SingularAttributeImpl[org.eclipse.persistence.mappings.DirectToFieldMapping[prodDesc-->PRODUCT_LISTS.prodDesc]][EntityTypeImpl@3567635:ProductList[javaType:class test.entity.ProductList描述符:RelationalDescriptor(test.entity.ProductList-->[DatabaseTable(产品列表)]),映射:5]]不存在

更新2

Expression<String> stringConcat = 
criteriaBuilder.concat(criteriaBuilder.concat(rootPr.get(ProductList_.prodDesc), " # "), 
rootEmp.get(ProductEmp_.empNo));

我在这里看到两个问题。首先,需要属性名,因此无法传递字符串连接。其次,如果要选择字符串连接的结果,必须使用而不是使用
+
运算符连接的纯java字符串

因此,我想尝试一下:

Expression<String> stringConcat = criteriaBuilder.concat(
    criteriaBuilder.concat(rootPr.get(ProductList_.prodDesc), " # "), 
    rootEmp.get(ProductEmp_.empNo));

criteriaQuery.multiselect(root.get(ProductCatalogue_.userId), 
    root.get(ProductCatalogue_.productList), 
    criteriaBuilder.selectCase()
        .when(criteriaBuilder.equal(root.get(ProductCatalogue_.prodId),"ZCX"), stringConcat)
        .otherwise(rootPr.get(ProductList_.prodDesc)));

在JPA标准中,NVL有一个等价物。
CriteriaBuilder.coalesce()
。CASE也有一个等价物:
CriteriaBuilder.selectCase()
@NeilStockton我尝试过使用Case,但是它导致了错误,我用我的Case语句和异常更新了我的问题。请看一看。不确定我在
multiselect
中的Case语句是否正确!@Ish我尝试过使用Case,但是它导致了错误,我用我的Ca更新了我的问题se语句和例外。请您看一看。案例的“Others()”部分在哪里?(即ELSE)@NeilStockton
Others()
我用hypen放了一个字符串,我更新了问题它是
路径
还是
表达式
?我尝试了路径,但是我得到了以下错误
javax.persistence.criteria.Path预期,但找到了javax.persistence.criteria.Expression
。因此我尝试了
表达式
。我更新了我的q关于表达式代码段的问题。您能更新您的答案吗?因为我使用了表达式而不是路径,并且能够消除缺少括号的错误。
THEN (t0.prodDesc = ?) 
Expression<String> stringConcat = criteriaBuilder.concat(
    criteriaBuilder.concat(rootPr.get(ProductList_.prodDesc), " # "), 
    rootEmp.get(ProductEmp_.empNo));

criteriaQuery.multiselect(root.get(ProductCatalogue_.userId), 
    root.get(ProductCatalogue_.productList), 
    criteriaBuilder.selectCase()
        .when(criteriaBuilder.equal(root.get(ProductCatalogue_.prodId),"ZCX"), stringConcat)
        .otherwise(rootPr.get(ProductList_.prodDesc)));
Expression<Long> userId = criteriaBuilder.selectCase()
    .when(criteriaBuilder.isNull(rootEmp.get(ProductEmp_.userId)), root.get(ProductCatalogue_.userId))
    .otherwise(rootEmp.get(ProductEmp_.userId));