HQL query highlighting and autocompletion for generic string
Answered
We maintain a lot of HQL queries as constant Strings in an interface.
public interface SomeQueries {
String PUPPIES = "select p from Dog d join d.puppies p";
}
The queries are maintained in a single interface to make them testable.
These strings are then used throughout the whole project for the creation of queries using an EntityManager.
EntityManager em;
Query tQuery = em.createQuery(SomeQueries.PUPPIES);
Is it possible to use HQL highlighting autocompletion and suggestions in these strings. Maybe is there a way to somehow annotate a string to indicate to IntelliJ to treat the string like a HQL-Query? How does IntelliJ determine which strings are HQL queries, since a String in the same class works fine:
EntityManager em = null;
String tQueryString = "select p from Dog d join d.puppies p";
Query tQuery = em.createQuery(tQueryString);
Please sign in to leave a comment.
Hello Sebastian,
Please see Using Language Injections related help topic. You can inject HQL into any string via intention action:
or using comments: