SqmRoot not yet resolved to TableGroup

This was asked numerous times before:

You have to copy this differently i.e. with the SqmStatement#copy method. Look at the definition of CriteriaQuery#getRoots(), it says mutations to the list shall not alter the query.