Reputation: 996
I'd like to implement simple jpa named queries with IntelliJ IDEA using final Strings to defined parameters. But the inspector do't like it and told me 'unexpected token' to the ':' on the end of the first part of the query. How can I suppress the inspection or how can I convince the inspection to accept that.
@NamedQueries({
@NamedQuery(name = TaxonEntity.selectBytaxonId,
query = "SELECT t FROM TaxonEntity t WHERE t.taxonId =:" + TaxonEntity.TAXON_ID)
})
@Entity
public class TaxonEntity {
static public final String selectBytaxonId = "TaxonEntity.selectBytaxonId";
static public final String TAXON_ID = "taxonId";
....
}
Thanks in advance,
Medrod
UPDATE: The IntelliJ IDEA will accept the query if after the constant a String will be appended.
@NamedQueries({
@NamedQuery(name = TaxonEntity.selectBytaxonId,
query = "SELECT t FROM TaxonEntity t WHERE t.taxonId =:"+TaxonEntity.TAXON_ID+"")
})
Upvotes: 1
Views: 2939
Reputation: 80340
What SQL database are you using?
As I remember the equal operator in SQL is =
not =:
.
The IDEA inspector complaining is probably not java inspector, but SQL inspector. IDEA is quite smart and knows what is what.
Upvotes: 0
Reputation: 139931
Try this instead
@NamedQueries({
@NamedQuery(name = TaxonEntity.selectBytaxonId,
query = "SELECT t FROM TaxonEntity t WHERE t.taxonId = " + TaxonEntity.TAXON_ID)
})
@Entity
public class TaxonEntity {
static public final String selectBytaxonId = ":TaxonEntity.selectBytaxonId";
Alternatively you may just want to make the whole query a constant. It'd be a bit more readable.
Upvotes: 2
Reputation: 328614
As a workaround, create a second constant which includes the :
.
Upvotes: 1