Migration: org.hibernate.sql.ast.SqlTreeCreationException: Could not locate TableGroup

Hi,

We are migrating from 5.6.9 to 6.1.7 We are getting org.hibernate.sql.ast.SqlTreeCreationException: Could not locate TableGroup while executing the below criteria query

public Long countCriteriaResult(List<Predicate> predicates) {
        try {
            CriteriaBuilder builder = entityManager.getEntityManagerFactory().getCriteriaBuilder();
            CriteriaQuery<Long> countQuery = builder.createQuery(Long.class);
            Root<table1> actCount = countQuery.from(table1.class);

            countQuery.select(builder.count(actCount));
            countQuery.where(predicates.toArray(new Predicate[0]));
    
            return this.entityManager.createQuery(countQuery.distinct(true)).getSingleResult();
        } catch (NoResultException resultEx) {
            LOG.warn("No result : {}", resultEx.getMessage() );
        } catch (Exception ex) {
            LOG.error("Other error: {}", ex.getMessage());
        }
        return Long.valueOf(0);
    }

this method is called after another query that works well :

CriteriaBuilder builder = getRepository().getEntity().getEntityManagerFactory().getCriteriaBuilder();
      
        CriteriaQuery<table1> criteriaQuery= builder.createQuery(table1.class);
        Root<table1> actCom = criteriaQuery.from(table1.class);
        
        List<Pair<String, From<?, ?>>> froms = new LinkedList<>();
        froms.add(Pair.of("table1", actCom)); 
                
        List<Predicate> predicates = new LinkedList<>();
        predicates.addAll(ClientCriteriaConverter.getFilterPredicates(criteria, froms, builder));    
        criteriaQuery.where(predicates.toArray(new Predicate[0])); 
        CriteriaQuery.orderBy(ClientCriteriaConverter.getCriteriaOrdersFromCriteria(criteria, froms, builder));
                
        criteriaQuery.select(actCom);
        List<table1> items = getRepository().searchCriteriaPagedResult(page, pageSize, criteriaQuery);
        Long records = getRepository().countCriteriaResult(predicates);

and with :

public List<Table1> searchCriteriaPagedResult(int page, int pageSize, CriteriaQuery<Table1> criteriaQuery) {
        return this.entityManager.createQuery(criteriaQuery)
                .setMaxResults(pageSize)
                .setFirstResult((page-1) * pageSize )
                .getResultList();
    }

Hibernate ORM 6.1 is not supported. Please update to the latest version and read Maintenance Policy - Hibernate

Hello,
I update my appli to 6.4.4 and then I have a new error :

java.lang.IllegalArgumentException: Already registered a copy: SqmBasicValuedSimplePath(maClasse(87790875978100).dateTime)
at org.hibernate.query.sqm.internal.SimpleSqmCopyContext.registerCopy(SimpleSqmCopyContext.java:29)
at org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath.copy(SqmBasicValuedSimplePath.java:54)

Community support is only provided for the latest stable version, which, at the time of writing, is ORM 6.6.
So unless you are a Red Hat customer and use a paid product that includes ORM 6.4, we can’t help you. Please upgrade to the latest version.

Even if we migrate to 6.6.9.Final, we still have the first error : Could not locate TableGroup

@zineb_c in that case, please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a new ticket in our issue tracker and attach that reproducer.