What causes IntelliJ to randomly recognize JPA relationships?
When creating a project from existing sources sometimes it decides to recognize the reationship mappings and sometimes it doesn't. This is also the case with JPQL queries, sometimes my Entities are recognized sometimes they are not. It is really frustrating, what configuration is necessary to get IntelliJ work correctly? I have added all the necessary facets to the projects.
Please sign in to leave a comment.
Hello Samuel,
Samuel Doyle wrote:
Correct persistence.xml should be configured for each JPA facet.
This can be verified in JPA facet settings.
If JPA annotations are used Language Level must be 1.5 and up and
javaee.jar must be in module classpath.
If XML metadata is used you may want to check whether mapping.xml
references are resolved correctly in persistence.xml.
There may be other issues depending on your configuration.
Gregory Shrago
I had the problem for a long time myself, the solution is the pretty much undocumented language injection mechanism. In short: u have to add a Parameter in the Language Injection menu where you bind String parameters of methods of a distinct class to a language, in the case of JPA to JPQL. That the language injection happens apparently randomly is because for instance for the EntityManager such a Parameter already exists, so whenever u call your EntityManager directly jpql is recognized, for example: entityManager.createQuery("select e from Entity e") should be recognized, while myDao.createQuery("select e from Entity e") is only recognized when a Parameter in the Language Injection menu is created for Class MyDao and the createQuery method of the class is bound to 'JPQL'. hth
As far as Language Injection is concerned you may want to check out our
blog.
http://blogs.jetbrains.com/idea/2009/03/user-defined-language-injection/
Tilman Rossmy wrote: