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

**URL:** <https://discourse.hibernate.org/t/migration-org-hibernate-sql-ast-sqltreecreationexception-could-not-locate-tablegroup/11070>\
**Category:** Hibernate ORM\
**Created:** [February 17, 2025, 3:05pm UTC](https://discourse.hibernate.org/t/migration-org-hibernate-sql-ast-sqltreecreationexception-could-not-locate-tablegroup/11070 "2025-02-17T15:05:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zineb\_c](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/zineb_c/32/3849_2.png) [@zineb\_c](https://discourse.hibernate.org/u/zineb_c)\
**Post date:** [February 17, 2025, 3:05pm UTC](https://discourse.hibernate.org/t/migration-org-hibernate-sql-ast-sqltreecreationexception-could-not-locate-tablegroup/11070/1 "2025-02-17T15:05:39Z")

</div>

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

```auto
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 :

```auto
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 :

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

```

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [February 18, 2025, 9:32am UTC](https://discourse.hibernate.org/t/migration-org-hibernate-sql-ast-sqltreecreationexception-could-not-locate-tablegroup/11070/2 "2025-02-18T09:32:59Z")

</div>

Hibernate ORM 6.1 is not supported. Please update to the latest version and read [Maintenance Policy - Hibernate](https://hibernate.org/community/maintenance-policy/)

---

<div class="post-metadata">

**Author:** ![zineb\_c](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/zineb_c/32/3849_2.png) [@zineb\_c](https://discourse.hibernate.org/u/zineb_c)\
**Post date:** [February 24, 2025, 10:44am UTC](https://discourse.hibernate.org/t/migration-org-hibernate-sql-ast-sqltreecreationexception-could-not-locate-tablegroup/11070/3 "2025-02-24T10:44:08Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [February 24, 2025, 5:33pm UTC](https://discourse.hibernate.org/t/migration-org-hibernate-sql-ast-sqltreecreationexception-could-not-locate-tablegroup/11070/4 "2025-02-24T17:33:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zineb\_c](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/zineb_c/32/3849_2.png) [@zineb\_c](https://discourse.hibernate.org/u/zineb_c)\
**Post date:** [February 28, 2025, 2:44pm UTC](https://discourse.hibernate.org/t/migration-org-hibernate-sql-ast-sqltreecreationexception-could-not-locate-tablegroup/11070/5 "2025-02-28T14:44:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [March 3, 2025, 8:45am UTC](https://discourse.hibernate.org/t/migration-org-hibernate-sql-ast-sqltreecreationexception-could-not-locate-tablegroup/11070/6 "2025-03-03T08:45:34Z")

</div>

@zineb_c in that case, please try to create a reproducer with our [test case template](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) and if you are able to reproduce the issue, create a new ticket in our [issue tracker](https://hibernate.atlassian.net/browse/HHH) and attach that reproducer.
