Is there any convention how to name parameters in JPQL?Because today after some debugging I realized that I can’t put inside name for example colon.
Also I discovered second problem, from some reason I can’t use use constants as parameter names. I will always get a
org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:466)
Here is my code
@NamedQueries({
@NamedQuery(
name=Lookup.GET_LOOKUP_DATA_QUERY,
query="SELECT t.textShort, lookup.metaCode, lookup.tableName FROM Lookup lookup, Txt t" +
" WHERE (lookup.metaCode = t.txtHeadCode OR t.txtHeadCode IS NULL) AND lookup.module.id =:" + Lookup.PARAM_MODULE_ID +
" AND lookup.metaCode IN (:" + Lookup.PARAM_LOOKUP_META_CODES + ") AND t.lang.metaCode = 'lang_cz'")
})
@Entity
@Table(name = "TABLE")
public class Lookup {
private static final long serialVersionUID = 1L;
public static final String GET_LOOKUP_DATA_QUERY = "Lookup.GetLookupDataQuery";
public static final String PARAM_MODULE_ID = "Lookup.PARAM_MODULE_ID";
public static final String PARAM_LOOKUP_META_CODES = "Lookup.PARAM_LOOKUP_META_CODES";
@Id
@Column(name ="META_CODE")
private String metaCode;
@Column(name = "ID")
private Long id;
@ManyToOne
@JoinColumn(name="MODULE_ID")
private Module module;
}
+ getters, setters and other properties
Provider is Hibernate but query is written in pure JPA
So does anyone know how to solve this?
You cannot use characters that are not part of valid identifier as defined by Character.isJavaIdentifierPart. named parameters are defined in JPA 2.0 specification:
Using constants when query string for @NamedQuery is built does not cause problems. It is compile time construct and Hibernate is not aware of was this query built with constants or not.
In your current query all named parameters are invalid. That is because of ‘.’. According Character.isJavaIdentifierPart it is not one of the valid characters.