title: Case Statement and NVL with Criteria API - IllegalArgumentException: The attribute [SingularAttributeImpmappings.DirectToFieldMapping
body: <p>I am able to build criteria using JPA Criteria Builder</p>
  
  <p>Java code snippet</p>
  
  <pre><code>cq.multiselect(root.get(ProductCatalogue_.userId),root.get(ProductCatalogue_.productList));
  
      Join&lt;ProductCatalogue, ProductList&gt; joinList = root.join(ProductCatalogue_.productList, JoinType.LEFT);
      Join&lt;ProductCatalogue, ProductEmp&gt; joinEmp = root.join(ProductCatalogue_.productEmp, JoinType.LEFT);
  </code></pre>
  
  <p>Problem I am facing here not sure how to use case statement with the above code and nvl which I have used in SQL    </p>
  
  <p><strong>Update 1</strong></p>
  
  <pre><code>criteriaQuery.multiselect(root.get(ProductCatalogue_.userId),
  root.get(ProductCatalogue_.productList),criteriaBuilder.selectCase().
  when(criteriaBuilder.equal(root.get(ProductCatalogue_.prodId),"ZCX"),
  rootPr.get(ProductList_.prodDesc + " # " + 
  rootEmp.get(ProductEmp_.empNo))).otherwise(rootPr.get(ProductList_.prodDesc));
  </code></pre>
  
  <p>Exception</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: The attribute [SingularAttributeImpl[org.eclipse.persistence.mappings.DirectToFieldMapping[prodDesc-->PRODUCT_LISTS.prodDesc]]] from the managed type [EntityTypeImpl@3567635:ProductList [ javaType: class test.entity.ProductList descriptor: RelationalDescriptor(test.entity.ProductList --> [DatabaseTable(PRODUCT_LISTS)]), mappings: 5]] is not present.</p>
  </blockquote>
  
  <p><strong>Update 2</strong></p>
  
  <pre><code>Expression&lt;String&gt; stringConcat = 
  criteriaBuilder.concat(criteriaBuilder.concat(rootPr.get(ProductList_.prodDesc), " # "), 
  rootEmp.get(ProductEmp_.empNo));
  </code></pre>
  
  <p>Error  </p>
  
  <blockquote>
    <p>missing right parenthesis </p>
  </blockquote>
  
  <p>because then part of SQL has a question mark as it is expecting a parameter</p>
  
  <pre><code>THEN (t0.prodDesc = ?) 
  </code></pre>