I have the following:
<class name="show"...>
...
<many-to-one name="icon" ... lazy="proxy" fetch="join" not-found="ignore" >
<column name="Icon_ID" not-null="false" />
</many-to-one>
</class>
<class ... table="icon" lazy="true">
...
<id name="id" column="ID" type="long" unsaved-value="-1">
<generator class="identity" />
</id>
</class>
Icon and show get populated in one case, through the following named query
<sql-query name="get-shows">
<return alias="ps" class.../>
...
<return-join alias="icon" property="ps.icon">
<return-property name="id" column="ps.Icon_ID2" />
<return-property name="url" column="ps.Icon_Url" />
<return-property name="description" column="ps.Icon_Description" />
...
</sql-query>
Like on many posts I've seen, show doesn't always have an icon, so it's a one-to-zero or more relation. I'm getting an exception of course:
org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
Caused by: java.sql.SQLException: Column 'Icon_ID3_1_1_' not found. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920) at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1163) at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:3055) at com.mchange.v2.c3p0.impl.NewProxyResultSet.getLong(NewProxyResultSet.java:2625) at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:74) at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
I'm no Hibernate expert, but this is what I understand: Because of the many-to-one, Hibernate wants to instantiate an Icon. But the column_id in the resultSet is null (since there is no icon).
Question 1: Am I understanding this correctly?
Question 2: Could I overcome this using a custom Tupolizer / proxy?
I've spent a few hours on (2), but didn't get very far. Question 3: If the answer to question (2) is yes, then can someone please point me to a SIMPLE (!) example of how to address this using a tuplizer/proxy. The examples I've googled are way too complex (that lazy loading example you get endlessly when you google), and the one in the documentation is probably too simple (?)
PS. Question 4: Why doesn't not-found="ignore" work in this case, where the whole result set comes from a named query? or is that actually the problem?
PS 2. Yes, I've seen this: https://forum.hibernate.org/viewtopic.php?t=949458
Thanks!