title: java.lang.IllegalArgumentException: Selection items in a multi-select cannot contain compound tuple-valued elements in JPA CriteriaQuery example
body: <p>I am developing <strong>Spring + Spring Data JPA + JPQL Hibernate Criteria scenario</strong> in my project. In this project I developed the following test case and when I'm executing it, I see the following error. I know its a small mistake but dont know what it is. Please guide.</p>
  
  <pre><code>java.lang.IllegalArgumentException: Selection items in a multi-select cannot contain compound tuple-valued elements
      at org.hibernate.jpa.criteria.CriteriaBuilderImpl.checkMultiselect(CriteriaBuilderImpl.java:158)
      at org.hibernate.jpa.criteria.CriteriaBuilderImpl.tuple(CriteriaBuilderImpl.java:185)
      at org.hibernate.jpa.criteria.CriteriaQueryImpl.multiselect(CriteriaQueryImpl.java:110)
      at org.hibernate.jpa.criteria.CriteriaQueryImpl.multiselect(CriteriaQueryImpl.java:101)
      at com.scheduler.test.ProductTest.testCriteriaQuerysMultiselect(ProductTest.java:110)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  </code></pre>
  
  <p><strong>ProductCriteriaJPQLTest.java</strong></p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = "classpath:application-context.xml")
  @Transactional
  @Rollback
  public class ProductCriteriaJPQLTest {
  
      @PersistenceContext
      private EntityManager em;
  
      private CriteriaBuilder cb;
      CriteriaQuery&lt;Object&gt; criteriaQuery;
  
      @Before
      public void before() {
          cb = em.getCriteriaBuilder();
          criteriaQuery = cb.createQuery();
      }
      // CriteriaQuery's multiselect
      @Test
      public void testCriteriaQuerysMultiselect(){
          CriteriaQuery&lt;Tuple&gt; q = cb.createTupleQuery();
          Root&lt;Product&gt; c = q.from(Product.class);
          q.multiselect(cb.tuple(c.get("productCode"), c.get("productVendor"), c.get("productline").get("productLine")));
  
          List&lt;Tuple&gt; results = em.createQuery(q).getResultList();
          for (Tuple t : results) {
              System.out.println("ProductCode: " + t.get(0) + ", ProductName: " + t.get(1)+", ProductVendor : "+t.get(2));
          }
      }
  }
  </code></pre>
  
  <p><strong>Product.java</strong></p>
  
  <pre><code>@Entity
  @Table(name="products")
  @NamedQuery(name="Product.findAll", query="SELECT p FROM Product p")
  public class Product implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
  //  @GeneratedValue(strategy=GenerationType.AUTO)
      private String productCode;
  
      private double buyPrice;
  
      private double msrp;
  
      @Lob
      private String productDescription;
  
      private String productName;
  
      private String productScale;
  
      private String productVendor;
  
      private short quantityInStock;
  
      //bi-directional many-to-one association to Orderdetail
      @OneToMany(mappedBy="product")
      private List&lt;Orderdetail&gt; orderdetails;
  
      //bi-directional many-to-one association to Productline
      @ManyToOne
      @JoinColumn(name="productLine")
      private Productline productline;
       // Assume the setters and getters are present
      }
  }
  </code></pre>
  
  <p>Please let me know if you need any other info.</p>
  
  <p>EDIT-1 : As suggested, I tried below but still its not working</p>
  
  <pre><code>@Test
      public void testCriteriaQuerysMultiselect(){
          CriteriaQuery&lt;Tuple&gt; query = cb.createTupleQuery();
  
          Root&lt;Product&gt; product = query.from(Product.class);
          query.multiselect(cb.tuple(product.get("productCode")));
  
          List&lt;Tuple&gt; results = em.createQuery(query).getResultList();
          for (Tuple t : results) {
              System.out.println("ProductCode: " + t.get(0) + ", ProductName: " + t.get(1)+", ProductVendor : "+t.get(2));
          }
      }
  </code></pre>