While upgrating Hibernate version from 4.3.7 to 6.1.1 I'm getting an Exception running a piece of code that used to work and is found in several tutorials and examples The simplest code I can build to show the behavior is:
CriteriaBuilder builder = em4.getCriteriaBuilder();
CriteriaQuery<Persona> cq = builder.createQuery(Persona.class);
Root<Persona> rootClaseGrid = cq.from(Persona.class);
cq.select(rootClaseGrid);
Predicate conjuncion = builder.conjunction();
Predicate expr = builder.equal(rootClaseGrid.get("documento"), "AAAA");
conjuncion.getExpressions().add(expr);
Last line throws:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.base/java.util.AbstractList.add(AbstractList.java:153)
at java.base/java.util.AbstractList.add(AbstractList.java:111)
at pruebas.PruebaHM.main(PruebaHM.java:181)
Debugging Hibernate code shows that method "getExpressions" resolves in class "org.hibernate.query.sqm.tree.predicate.AbstractSqmPredicate", with code:
@Override
public List<Expression<Boolean>> getExpressions() {
return Collections.emptyList();
}
in fact returning always an emptyList of java.util.AbstractList, trying to add elements always throws UnsupportedOperationException:
public void add(int index, E element) {
throw new UnsupportedOperationException();
}
Older versions (for instance 4.3.7) manage a list of Expression<Boolean>, the last line in the code above resolves in class "org.hibernate.jpa.criteria.predicate.CompoundPredicate" :
@Override
public List<Expression<Boolean>> getExpressions() {
return expressions;
}
Thanks in advance |