Created
          February 9, 2017 12:26 
        
      - 
      
 - 
        
Save thjanssen/6bc1df67975ae93bff90b5cd73136a48 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | CriteriaBuilder cb = em.getCriteriaBuilder(); | |
| CriteriaQuery cq = cb.createQuery(Book.class); | |
| Root root = cq.from(Book.class); | |
| // call the database function calculate | |
| ParameterExpression doubleParam1 = cb.parameter(Double.class); | |
| ParameterExpression doubleParam2 = cb.parameter(Double.class); | |
| cq.where(cb.greaterThan(doubleParam2, cb.function(“calculate”, Double.class, root.get(Book_.price), doubleParam1))); | |
| TypedQuery q = em.createQuery(cq); | |
| q.setParameter(doubleParam1, 10.0D); | |
| q.setParameter(doubleParam2, 40.0D); | |
| List books = q.getResultList(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment