Hi.
I don't want hibernate to persist criteriaType property, so I annotated getCriteriaType method with @Transient annotation. Here is the code:
@Entity
@DiscriminatorValue(value = "java.lang.String")
public class StringFilterCriteria extends FilterCriteria {
private static final long serialVersionUID = -1849845246809052465L;
private static final String TYPE = String.class.getName();
public StringFilterCriteria() {
this(new String[] { "" });
}
public StringFilterCriteria(String[] filterTemplates) {
this.filterTemplates = filterTemplates;
this.templatesCount = 1;
}
protected void validate(String[] newTemplates) throws FilterFormatException {
if (newTemplates.length != templatesCount)
throw new IllegalArgumentException("Incorrect parameters count");
}
@Transient
public String getCriteriaType() {
return TYPE;
}
public Criterion buildCriterion(String fieldName) {
Criterion criterion = Expression.like(fieldName, filterTemplates[0], MatchMode.EXACT);
return criterion;
}
public String buildWhereCondition(String fieldName, String persistetObjectQueryAlias, Map<String, QueryParameter> placeholders) {
StringBuilder whereStringBuilder = new StringBuilder(persistetObjectQueryAlias);
whereStringBuilder.append(".").append(fieldName);
whereStringBuilder.append(" like :").append(fieldName);
whereStringBuilder.append(" ");
placeholders.put(fieldName, new QueryParameter(fieldName, filterTemplates[0], QueryParameterType.STRING));
return whereStringBuilder.toString();
}
@Override
public void buildWhereClausePart(StringBuilder query, String persistetObjectFieldName, String persistetObjectQueryAlias, Map<String, Object> queryNamedParameterNameValueMap) {
query.append(persistetObjectQueryAlias).append(".").append(persistetObjectFieldName);
query.append(" like :").append(persistetObjectFieldName);
queryNamedParameterNameValueMap.put(persistetObjectFieldName, filterTemplates[0]);
}
}
But I'm retrieving the following exception:
Could not find a setter for property criteriaType in class ru.runa.af.presentation.filter.StringFilterCriteria
I have no idea about its cause and will be grateful for any help.
|