title: Query for numerical varchars and compare them, with querydsl
body: <p>Lets say I have three tables, profile and profile_elements (one to many association) and element_type.</p>
  
  <p>profile_elements has all elements of the profile and also the element_type_id as a foreign key to element_type table and has a column "value" that is VARCHAR.</p>
  
  <p>I want to make an advanced search into profile_elements. When I work with Strings of course there is no problem but if for example I want to make a comparison (greater than etc) with values of the "value" column I cant, even if I know that i.e. when the element_id=1 then these values gonna be numerical varchars. 
  I've tried to build a predicate like </p>
  
  <pre class="lang-java prettyprint-override"><code>QprofileElements.profileElements.any().elementId.eq(1).and(QprofileElements.profileElements.any().value.castToNum(Long.class).gt(12345)
  </code></pre>
  
  <p>but hibernate handles it as two separate select-from-where queries and it tries to cast to long all values of the columns so an error occurs when it tries to convert a value that contains characters. I even managed to make it so hibernate sees it as one query of the form </p>
  
  <pre><code>where element_id=1 AND cast(value)&gt;12345
  </code></pre>
  
  <p>but it still has the same problem.</p>
  
  <p>Is there a way to overcome this problem with querydsl or something else? And if it isn't, is there a way to construct this query </p>
  
  <pre class="lang-sql prettyprint-override"><code>select * 
  from(
    (select * from profile_element pe where pe.element_id=1)
  ) as sq 
  where cast(sq.value as int8)&gt;12345 
  </code></pre>
  
  <p>with querydsl? </p>
  
  <p>I've tried JPAExpressions too, even when().then(), nothing seems to work </p>
  
  <p>Versions</p>
  
  <ul>
  <li>Postgresql 9.5</li>
  <li>hibernate 5.4</li>
  <li>querydsl 4.2.1</li>
  </ul>