In a complicated class hierarchy with multiple inheritance strategies, there is a ManyToOne association ("Task") in a join table entity ("SubEntity") within the hierarchy. A criteria query is used to load a subset of the entities within the hierarchy based on a property value of the top level entity type:
Criteria criteria = session.createCriteria(TheTopLevelEntityClass.class, "r");
criteria.add(Restrictions.eq("propertyOne", "some_value"));
List list = criteria.list();
When the query is executed, there are two selects. The second select should include the foreign key column in the SubEntity table that links to the Task table is missing from the result set. Hibernate attempts to find the column value in a row and fails with:
org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.loader.Loader.doList(Loader.java:2620) at org.hibernate.loader.Loader.doList(Loader.java:2600) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429) at org.hibernate.loader.Loader.list(Loader.java:2424) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1774) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363) ... Caused by: org.h2.jdbc.JdbcSQLException: Column "TASK2_111_0_" not found ... ... at org.h2.jdbc.JdbcResultSet.getLong(JdbcResultSet.java:655) at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:63) at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238) at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:234) at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:224) at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:169) at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2738) at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1729) at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1655) at org.hibernate.loader.Loader.getRow(Loader.java:1544) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:727) at org.hibernate.loader.Loader.processResultSet(Loader.java:972) at org.hibernate.loader.Loader.doQuery(Loader.java:930) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doList(Loader.java:2617) ...
|