How do I get rid of a "SELECT expected" error?
Hello,
I'm using IDEA 8.0,1, spring and hibernate and I have a named query in one of my DTOs. The annotation looks like this:
@NamedQueries({@NamedQuery(name = "UnitType.findByName",
query = "FROM CharacterType WHERE name = :name")})
And Intellij gives me an error at the 'f' of the FROM, saying, "SELECT expected (e.g. 'SELECT <select_expression> FROM <variable_declarations>')".
This is marked as an error which is really annoying and I can't figure out how to turn this off. I've disabled the SQL plugin, I've looked for a relevant error to turn off in Project Settings -> Errors but can't find one, the red lightbulb doesn't show up when I put my cursor over the error, alt+enter doesn't do anything either. Is this a bug? How do I turn this error off?
Attached is a screenshot of the error.
Attachment(s):
select_expected.jpg
请先登录再写评论。
Hello Dan,
Please, check Settings / Language injection / Injection tab / Parameters
tree. There find NamedQuery annotation and check what language is mapped
to "query" parameter. For me it is JPAQL, and a query starting with "from"
is Ok. But maybe this setting was somehow changed on your side.
Alexander.
In addition to my answer: just notice that there are at least 2 NamedQueries
annotations: one from javax.persistence and another is from Hibernate. So,
check annotation's package in settings.
Alexander.
OK, thanks for the advice. But, I think that I have it set the way it should be. I've never gone in here before so I don't think I changed anything. I've attached a screenshot of how my settings look but I still get this error. Is there anything else that could cause this problem?
BTW, when I change the ID to "generic SQL", the error goes away. But that doesn't seem ideal. I think I could get some cool benefits if I left it as JPAQL or EJBQL. So, I'm still looking for help on this.
Thanks,
Dan
Attachment(s):
namedquery.jpg
Do you have you a hibernate facet in you project?
A query starting with "FROM" is not valid JPAQL.
IIRC IDEA only allows hibernate specific extensions when there is a hibernate facet
(in addition to the JPA facet).
Dan Kaplan wrote: