public Predicate get_data(String field, String method, String value) throws Exception
{
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<student> cq = cb.createQuery(student.class);
Root<student> s = cq.from(student.class);
Predicate selected_field = null;
number = new BigDecimal(value);
if(method.equals("greaterThan") || method.equals("greaterThanOrEqualTo") ||
method.equals("lessThan") || method.equals("lessThanOrEqualTo"))
{
Method cbMethod = cb.getClass().getMethod(method,Expression.class,Comparable.class);
selected_field = (Predicate) cbMethod.invoke(cb,s.get(field), number);
}
else if(method.equals("eq"))
{
method = "equal";
Method cbMethod = cb.getClass().getMethod(method,Expression.class,Object.class);
selected_field = (Predicate) cbMethod.invoke(cb,s.get(field),number);
}
return selected_field;
}
public List<student> get(String search) throws Exception
{
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<student> cq = cb.createQuery(student.class);
Root<student> s = cq.from(student.class);
List<Predicate> selected_field = new ArrayList<>();
System.out.println(search);
List<String> query = Arrays.asList(search.split("And",0));
System.out.println(query.size());
List<String> fields = new ArrayList<>();
List<String> values = new ArrayList<>();
List<String> method = new ArrayList<>();
for (String str : query)
{
List<String> s1 = null;
int index_lt = str.indexOf('<');
int index_gt = str.indexOf('>');
int index_eq = str.indexOf('=');
if(index_lt != -1)
{
s1 = Arrays.asList(str.split("<",0));
method.add("lessThan");
}
else if(index_gt != -1)
{
s1 = Arrays.asList(str.split(">",0));
method.add("greaterThan");
}
else if(index_eq != -1)
{
s1 = Arrays.asList(str.split("=",0));
method.add("equal");
}
System.out.println("S1"+s1);
fields.add("student_"+s1.get(0));
values.add(s1.get(1));
}
for(int i = 0 ; i < fields.size() ; i++)
{
selected_field.add(get_data(fields.get(i),method.get(i),values.get(i)));
}
cq.where(cb.and(selected_field.toArray(new Predicate[] {})));
cq.where(predicatesarr);
System.out.println("where ends");
TypedQuery<student> search_query = em.createQuery(cq);
return search_query.getResultList();
}
когда я отправляю это http://localhost: 8080 /? Search = rollNo > 13, тогда это дает мне эту ошибку. org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'generatedAlias1.student_rollNo' [select generatedAlias0 from io.poc_task1.poc_task1.student as generatedAlias0 where generatedAlias1.student_rollNo>13]
Может кто-нибудь помочь мне с этим? Заранее спасибо.