SQL restrictions will allow you to add ad-hoc SQL to the criteria you are building. Simple enough, but we have made great strides to make this look easy for a developer but behind the scenes we take each sql you pass and compile it so we can abstract all the native Java types for you. This means that you can use it in a similar manner to executeQuery()
in CFML.
The method you will use for this restriction is sql()
The method takes in two arguments:
sql
- The ad-hoc query to execute. You can use positional parameters via the ?
placeholder.
params
- An array of parameters to bind the SQL with, can be simple values or a struct of a values and a supported type or a combination of both.
The parameters you bind the SQL with can be of two types
Plain values.
Typed values
If you use plain values, then we will INFER the type from it, which is not as accurate as using a typed value. A typed value is a struct with the value and a valid type.
Below you can see the TYPES
struct available in the criteria builder object which map the CFML types to the native Hibernate Types.
The inferred types we infer are the following and in the following order.
Binary
Boolean
Time
Date
uuid
float
numeric
url
string
text