Polymorphic query keeping order of selected tables

Hi,
I’m using an interface and polymorphic query like this:

public interface Taged {
   String getTag();
}

@Entity
class Car implements Taged {
  String tag
}

@Entity
class Plane implements Taged {
   String tag
}
...

By these tags we can categorize any of our entities, for Example “fast” or “loud”.
I want to query any Taged Entity by a given tag with limit & offset (to support pagination) like this

select from Taged where tag = :t order by tag

This performs actually two selects: One in Car-Table and one in Plane-Table.
The problem is: The order of the two queries is not deterministic org.hibernate.query.hql.internal.QuerySpliter and org.hibernate.query.sqm.tree.domain.SqmPolymorphicRootDescriptor use Set<EntityDomainType<?>> getImplementors()). This Set is not ordered, so each time i do my query, the order of DomainTypes may change
→ the Global result of my query is not deterministic and not usable for pagination

Suggestion:
IMHO it would be great, if the Set<EntityDomainType<?>> getImplementors() would be sorted (e.g. by Entity-Name) to keep the order each time the query is invoked. By this pagination would be possible.

1 Like

Sounds reasonable. Can you please create a Jira issue for this feature request? Ideally, you’d also contribute the fix for it :wink:

1 Like

Created Keep order of selected tables in polymorphic query and assigned it to myself.

1 Like

Does it all work without bugs?

What do you mean? Polymorphic queries are a supported feature for a long time…it’s just the order in which the sub-types are queried, that is not deterministic.

Usually any product has bugs, that’s why I asked.)))