|
When using the formula annotation, there are a number of potential uses that result in correct sql being generated.
1. Using a (valid) keyword may not be escaped properly. For example, the following sql is valid with oracle, but is escaped incorrectly:
@Formula("CAST(CODE AS INTEGER)")
which results in:
CAST(this_.CODE AS this_.INTEGER)
Integers are registered by hibernate as number(10,0) with oracle dialect (what I used to test), so it isn't recognized as a valid type/keyword. This can be fixed by registering the keyword with the dialect being used, which I believe has actually been recommended in the past (HH-2967). However, that also opens the possibility of misleading behaviour, since the tokens compared are lower-case, always. So, if the user registers "INTEGER" and uses "INTEGER" in their query, it would still be escaped incorrectly.
2. Registered column types for a given dialect also aren't being escaped properly, example:
@Formula("CAST(CODE AS FLOAT)")
results again in:
CAST(this_.CODE AS this_.FLOAT)
I would like to propose the following as potential fixes/improvements:
1. Custom keywords are always registered as lower-case, to keep in line with how keywords/functions/types are stored/compared. 2. Column types are also checked when determining the need to escape tokens.
|