-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Case sensitivity in JPQL queries #30
Comments
@glassfishrobot Commented |
@glassfishrobot Commented Please consider the addition or give reasons for not doing it! |
@glassfishrobot Commented |
@glassfishrobot Commented |
|
To be clear: keywords and identification variables are case-insensitive. The spec is actually silent on the question of whether entity names and field references in path expressions are case-sensitive (oops!), but it's strongly implied, and intended, that they are case-sensitive. I'm very surprised to hear that a entity names like That said, I think it was a mistake to say that identification variables are case-insensitive, and I wouldn't mind fixing that. But I can't think of a good and elegant way to fix it that doesn't imply breaking backward compatibility. So how about we just flatly state in the spec that |
and clarify rules around case-sensitivity see jakartaee#30
See proposed fix #449. |
Well, that's perhaps overstating the case slightly. We also need to consider disambiguating Now, in the BNF grammar defined by the specification, these actually are distinguished syntactically, since an Nevertheless, even if an expression like:
is ambiguous to the parser, it can easily be disambiguated during semantic analysis. And that's the only place an It's certainly quite clear from the BNF that |
and clarify rules around case-sensitivity see jakartaee#30
and clarify rules around case-sensitivity see #30
In JPA 2.0, JPQL is case insensitive. This means that contrary to Java code, an identifier can not be same name as an entity with the first letter in lower case.
For instance in the following query an underscore has to be added to make the name legal:
Other typical workarounds for this are abbreviating the identifier to e.g. "u", "usr" etc. Such names are rarely a best practice and actually against common advice for good naming given by books like Clean Code, etc.
I would like to request support for case sensitivity in some way, or alternatively to lift the requirement that identifiers may not have the same name as Entity classes. This last approach is taken by some persistence providers, e.g. Hibernate, which silently accepts identifiers having the same name as Entities.
One possible solution would be to use a setting, either per query or globally for the entire persistence unit. E.g.
The text was updated successfully, but these errors were encountered: