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.