Getting Table Aliases for JOINs

Hello, I hope you have a nice day!

I want to add some optimization hints to a statement. Specifically a JOIN ORDER for MySQL. To do that, I used

typedQuery.unwrap(org.hibernate.query.Query.class).addQueryHint("/*+ JOIN_ORDER(" + String.join(",", List.of("t1", "t2")) + ") */");

to add a query hint, and built a custom Dialect to insert that hint at the correct place in the statement. The only problem left is that I do not know the aliases Hinbernate uses for the joined tables. Is there a way to find those out?

I’m using Hibernate 7.3.1.Final, if that’s relevant.

The aliases are deterministic and based on the table name, but we don’t have a way to inject aliases into hints, so you will have to either rely on some sort of “well known” alias or do some sort of “parsing”.

Alright, thanks for the response.