title: How to properly cast string to number with JPA2 Criteria API?
body: <p>I am trying to write a query with subselect where a string is cast to a long.
  I'm probably missing something?</p>
  
  <p>Query looks like:</p>
  
  <pre><code>CriteriaBuilder cb = em.getCriteriaBuilder();
  CriteriaQuery&lt;Task&gt; query = cb.createQuery(Task.class);
  
  Root&lt;Task&gt; from = query.from(Task.class);
  
  Subquery&lt;Long&gt; subquery = query.subquery(Long.class);
  Root&lt;EntityKeyword&gt; fromKeyword = subquery.from(EntityKeyword.class); 
  subquery.select(fromKeyword.get(EntityKeyword_.relatedToId).as(Long.class));
  subquery.where(cb.like(fromKeyword.get(EntityKeyword_.keyword), term));
  
  query.where(cb.in(from.get(ModelEntity_.id)).value(subquery));
  </code></pre>
  
  <p>Where <strong>EntityKeyword_.relatedToId</strong> a is String that requires cast to Long.   </p>
  
  <p>But underlying Hibernate fails with exception:</p>
  
  <pre><code>Last cause: No data type for node: org.hibernate.hql.ast.tree.MethodNode 
   \-[METHOD_CALL] MethodNode: '('
      +-[METHOD_NAME] IdentNode: 'cast' {originalText=cast}
      \-[EXPR_LIST] SqlNode: 'exprList'
         +-[DOT] DotNode: 'entitykeyw1_.keyword' {propertyName=keyword,dereferenceType=ALL,propertyPath=keyword,path=generatedAlias1.keyword,tableAlias=entitykeyw1_,className=l.i.s.m.s.EntityKeyword,classAlias=generatedAlias1}
         |  +-[ALIAS_REF] IdentNode: 'entitykeyw1_.id' {alias=generatedAlias1, className=l.i.s.m.s.EntityKeyword, tableAlias=entitykeyw1_}
         |  \-[IDENT] IdentNode: 'keyword' {originalText=keyword}
         \-[IDENT] IdentNode: 'int8' {originalText=int8}
  </code></pre>
  
  <p>No idea what's wrong. Any help is appreciated.</p>
  
  <p>I'm using Hibernate 3.6.8-Final</p>