I am trying to create a generic method that defines a search. The search will receive the field name and the value to be searched as input parameters, not the object itself.
The problem is that I am getting the following errors in the 'return' line:
Multiple markers at this line
- Type safety: The method from(Class) belongs to the raw type AbstractQuery. References to generic type AbstractQuery<T> should be parameterized
- Type safety: The method where(Expression) belongs to the raw type CriteriaQuery. References to generic type CriteriaQuery<T> should be parameterized
- Illegal class literal for the type parameter T
- The method findOne(Example<S>) in the type QueryByExampleExecutor<T> is not applicable for the arguments (CriteriaQuery)
public abstract class ModelController<T extends HasId, R extends ModelRepository<T>> {
private T _findId(String field, String needle) {
EntityManager em;
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery();
// Here I got the errors
return repository.findOne(cq.where(cb.equal(cq.from(T.class).get(field), needle)));
}
}
Any clues?