@DiscriminatorColumn alias in native SQL

Hi all,

this question is probably very basic, so basic that noone asked about it before because the solution is obvious for everyone but me … at least I haven’t found anything about it.

I’m trying to migrate someone else’s code from Hibernate 5.3.7 to 6.5.2 and have a problem with a SINGLE_TABLE inheritance entity.

It has a @DiscriminatorColumn(name=“COL_NAME”). I want to migrate a native SQL query, not much more complex than this (but with a big native WHERE):

createNativeQuery(“SELECT {e.*} FROM table e”, Entity.class, “e”)

What I get is:
Caused by: org.hibernate.exception.GenericJDBCException: Unable to find column position by name: COL_NAME [Ungültiger Spaltenname] [n/a]

My conclusion: when searching for the Discrimnator-Field he doesn’t look at the Column Aliases he just generated for “{e.*}”. I’ve turned on SQL logging, and I can see he properly selects the column and generates an alias.

I can fix it by explicitly adding the discriminator column:
createNativeQuery(“SELECT {e.*}, COL_NAME FROM table e”, Entity.class, “e”)

, but is this the intended way or am I doing something wrong?

Thank you for your help!

Marcus.

Hello @zpneun, your problem sounds very similar to this open issue Jira.

Someone’s already tried to fix it and proposed a change, but the issue is still open, so I suggest watching it to receive any updates and voting for it to increase its visibility. Thanks for reaching out.

Hi Marco,

thanks for the link! Well if it’s an open bug, then it is okay for me to go with my workaround. Just wanted to be sure not to do something completely wrong.

That’s fine, perfect, thank you!

Marcus.