title: How To Select literals in QueryDSL
body: <p>Im currently working on a project that uses queryDSL and hibernate wherein it requires a select literal. Following the examples posted <a href="https://stackoverflow.com/questions/18691317/querydsl-how-to-select-literals-as-part-of-a-sqlsubquery">here</a> i have:</p>
  
  <pre><code>createQuery().
     from(path()).
        where(specification().getPredicate()).
            list(
     ConstructorExpression.create(Foo.class, Expressions.constant(BigDecimal.ONE)));
  </code></pre>
  
  <p>where Foo class has a constructor which accepts a BigDecimal. 
  When running this in test, i get</p>
  
  <pre><code>org.hibernate.QueryException: Parameters are only supported in SELECT clauses when used as part of a INSERT INTO DML statement
      at org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:146)
  </code></pre>
  
  <p>changing this to:</p>
  
  <pre><code>createQuery()
     .from(path()).
         where(specification().getPredicate())
             .list(
  ConstructorExpression.create(Foo.class, NumberTemplate.create(BigDecimal.class, "1.0")));
  </code></pre>
  
  <p>produces a different stacktrace:</p>
  
  <pre><code>java.lang.IllegalArgumentException: argument type mismatch
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
      at com.mysema.query.types.ConstructorExpression.newInstance(ConstructorExpression.java:133)
      at com.mysema.query.jpa.FactoryExpressionTransformer.transformTuple(FactoryExpressionTransformer.java:50)
  </code></pre>
  
  <p>I tried changing the Foo class constructor to accept Integer and the query modified to use Integer as well for the sake of testing and it did produces the correct query:</p>
  
  <pre><code>createQuery()
     .from(path()).
        where(specification().getPredicate())
           .list(ConstructorExpression.create(LevelBoundary.class, NumberTemplate.create(Integer.class, "1")));
  </code></pre>
  
  <p>Is using NumberTemplate the correct way to select BigDecimal literals? The NumberTemplate docs specifies T extending Number and Comparable but fails on non Integer types. How do i properly select constants/literals in querydsl?</p>