Named query resolution

How does IDEA figure out what PU to use to find named queries? Right now it's barfing on most of my ejb3 facets, saying it can't find queries.

In my class I have:

@PersistenceContext(unitName = "timesheet")
private EntityManager entityManager;

I have a persistence facet, with META-INF/persistence.xml in the same module with the name 'timesheet', with exclude-unlisted-classes, and listing all the entities. The entities themselves contain the named queries, yet IDEA refuses to see them.

7 comments
Comment actions Permalink

I'm bumping this up since its gotten no responses. To clarify, every now and then the named queries seem to forget what PU they belong to, and all get highlighted as errors.

0
Comment actions Permalink

Hani, I'm seeing some quirks with the named query resolution as well. I've attached a screenshot of what it looks like for me (before.png).

One other interesting thing is that just by typing in the named query (for example, adding an extra space somewhere), the whole query reverts to a regular string (after.png).

Tobin



Attachment(s):
after.png
before.png
0
Comment actions Permalink

Hello Hani,

IDEA collects all named queries from the module and all modules with
persistence facets it depends on. @PersistenceContext/@PersistenceUnit
annotations are not taken into account.

Does JavaEE: Structure view show your persistence.xml and unit?
The setup you mention should work fine.

If the problem is still there please provide me with sample project
I can reproduce the problem with.

Regards,
Gregory Shrago


Hani Suleiman wrote:

How does IDEA figure out what PU to use to find named queries? Right
now it's barfing on most of my ejb3 facets, saying it can't find
queries.

In my class I have:

@PersistenceContext(unitName = "timesheet") private EntityManager
entityManager;

I have a persistence facet, with META-INF/persistence.xml in the same
module with the name 'timesheet', with exclude-unlisted-classes, and
listing all the entities. The entities themselves contain the named
queries, yet IDEA refuses to see them.

0
Comment actions Permalink

I'll keep an eye out for when it happens again. One case though where it does happen consistently is if the query name is dynamic, for example:

entityManager.createNamedQuery("navpoint.community" + (prefetch ? ".prefetch" : "")).setParameter("community", community.getName())

0
Comment actions Permalink

Confirmed Tobin's experience. Here's what happened:

Open a file that references a bunch of named queries, no errors shown for queries
Toolbar tells me file is out of date, I update project
Queries shown as errors

Now, if I edit any of the queries (add a space for example before or after a '=' symbol), then go back to the file that uses that query, it still shows up as error. However, if I try to use autocompletion on the string, the correct values show up, selected any of these (or editing the string in any way) causes a reparse which will then remove the error.

0
Comment actions Permalink

I should note here that I'm still using 6.0.5, so there are no JPA facets in play for me.

0
Comment actions Permalink

I still have this problem.

My Java EE: Structure view shows the JPA facets, but there are no entities under any of the nodes.

Here's one example persistence.xml:

Wibble com.foo.Bar true ]]>

0

Please sign in to leave a comment.