Tell IntelliJ which String is a JPA query

Because of a mix between ORM tools we need a layer of abstraction between our code and the JPA entitymanager.
But because of this IntelliJ does not recognize JPQL query strings.

In the attachment, I added the first 3 lines using the entitymanager directly. The lines below are the normal code we use. As you can see, highlighting (and also code completion) in the direct call works, while in the other line it doesn't.

Is there a way to tell IntelliJ how it can detect JPQL queries in strings?



Attachment(s):
screenshot.png
4 comments
Comment actions Permalink

Hi Bart,

We call it language injection and cool thing about it is that's its possible to configure the IDE to use custom rules for it. You can have a look into built-in jpa injection rules and build your custom one using them as example:

injection.png

Regards, Denis

0
Comment actions Permalink

This works as a charm!!

The only problem with it is that although the settings are under "Project Settings", they end up in the IDEA configuration folder instead of the project folder making it harder to share this configuration for the project

0
Comment actions Permalink

Sorry,

just found the move to project button in the Language Injections dialog.

Bart

0

Please sign in to leave a comment.