With Criteria API, reusing Predicates with subqueries we are getting this error:
{noformat}Already registered a copy: org.hibernate.query.sqm.tree.select.SqmSubQuery@4416e18d{noformat}
Without subqueries, we are getting other error
{noformat}org.hibernate.sql.ast.SqlTreeCreationException: Could not locate TableGroup{noformat}
Sample:
{noformat}CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<MyEntity> cq = cb.createQuery(MyEntity.class); Root<MyEntity> root = cq.from(MyEntity.class);
List<Predicate> predicates = getPredicates(cb,cq, root, "1");
cq.select(root).where(predicates.toArray(Predicate[]::new));
TypedQuery<MyEntity> q = entityManager.createQuery(cq);
long count = count(entityManager, predicates);{noformat}
Same code in hibernate 5 works fine.
Test case: [https://github.com/DanielNovo/hibernate-test-case-templates/commit/e6b5f461d3da4075bca35f1fc3305997ca191203|https://github.com/DanielNovo/hibernate-test-case-templates/commit/e6b5f461d3da4075bca35f1fc3305997ca191203|smart-link] |
|