-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Use EclipseLink JPQLParser
to parse JPQL queries
#2458
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
Comments
EclipseLink is only an optional dependency and we certainly don't want force Hibernate users to also depend on EclipsesLink. But I guess somewhere in the Hibernate code is a JPQL parser as well. |
Yeah is just realised that... IntelliJ tricked me here 😂
I just took a closer look at
I think this is a valid approach. We could expand |
Apparently there was an experimental version located https://github.com/hibernate/hibernate-hql-parser. It seems this work is no longer experimental since it will be part of I could not find the exact commit that verifies this but I assume since it is a official hibernate repo that this is true. |
How does this stack of feature tie into using the newly added JSqlParser? |
@gregturn the newly added JSqlParser is only used for native SQL queries. For JPQL queries we are using While working on JSQLParser I realised that using a proper parser only benefits the project in the long run since you do not have to tinker with complex regex (more reasons see in issue description). This is why I started to investigate if there are good alternatives, so we can get rid of the regex in QueryUtils. |
@DiegoKrupitza In light of your latest comments, then this makes sense, if you wish to proceed with working up a modification. |
@DiegoKrupitza Considering EclipseLink is an optional dependency, we could alter /**
* Creates a new {@link QueryEnhancer} for the given {@link DeclaredQuery}.
*
* @param query must not be {@literal null}.
* @return an implementation of {@link QueryEnhancer} that suits the query the most
*/
public static QueryEnhancer forQuery(DeclaredQuery query) {
if (qualifiesForJSqlParserUsage(query)) {
return new JSqlParserQueryEnhancer(query);
} else if (/* EclipseLink is on the classpath*/) {
return new EclipseLinkJPQLParserQueryEnhancer(query);
} else {
return new DefaultQueryEnhancer(query);
}
} This would let us outsource to EclipseLink if it were on the classpath. And eventually, when Hibernate gets their own parser on the classpath (Hibernate 6?), we can enable that as well. We can do this bit by bit. |
Yes this was what I was thinking about! I could not verify (as stated above) if the experimental parser of hibernate made it into Hibernate 6, but a big by bit integration would make the most sense to me. First start with EclipseLink and as soon as hibernate supports this also include hibernates support. If both Eclipse and Hibernate are on the classpath (is that even possible or makes sense to do it?) it would be great to configure which should dominate in this case. I was thinking about the situation where some undesired behaviour in Eclipselink/Hibernate (maybe a bug?) is happening and therefore maybe switch to the other implementation (only for the parser). |
If I find time I could start working on this but I can't promise since uni workload is sometimes unpredictable. |
Implemented `detectAlias()`, `getProjection()`, `getJoinAliases()`, `hasConstructorExpression()`. `applySorting(...)` and `createCountQueryFor(...)` is not implemented so far since I could not find a way to modify the parsed query so far. Related tickets spring-projects#2458
I looked closer at this issue and saw that an EclipseLink implementation of QueryEnhancer currently is not a wise decision. There are two "problems":
I suggest to revisit this issues later as soon as the API is stable and in the meantime focus on leveraging the Hibernates 6 parser (after spring data jpa upgrades to hibernate 6 #2423 ). |
Superceded by #2814. |
With #2814 merged to |
I have seen that there are few issues open, that are related to JPQL queries not parsed correctly.
distinct
phrase if from part of JPA query contains newline character #2341Since EclipseLink is already present in the project it does not bring in a new dependency.
JPQLParser
is located inorg.eclipse.persistence.internal.jpa.parsing.jpql
.Why use
JQPLParser
over the current approach? The current approach uses REGEX and String formatting magic that can be quite hard. A REGEX expression is quite limited and has less power than a full parser that utilizes the power of context free grammars. Using only REGEX is not a good idea since JPQL is not a regular language. Therefore JPQL cannot be represented only using REGEX. (see more here and here why REGEX is not powerful enough).The text was updated successfully, but these errors were encountered: