I have below <sql-query/> element present in one of the hibernate mapping file.
Code:
<sql-query name="metaobject.findByPartialKey_metaobject_for_structure">
<return class="Metaobject" />
select metaobjectno, structureno, name, description from metaobject where structureno = :structureno
</sql-query>
Metaobject class definition is something like this --
Code:
<class name="Metaobject" table="metaobject">
<composite-id name="comp_id" class="MetaobjectPK">
<key-property name="metaobjectno" column="metaobjectno" type="java.lang.Integer" length="3" />
<key-property name="structureno" column="structureno" type="java.lang.Integer" length="3" />
</composite-id>
<property name="name" column="name" type="java.lang.String" length="64" lazy="true" />
<property name="description" column="description" type="java.lang.String" length="128" lazy="true" />
<property name="lookup" column="lookup" type="java.lang.Character" length="1" lazy="true" />
<property name="persistent" column="persistent" type="java.lang.Character" length="1" lazy="true" />
....
....
</class>
When I try to execute the sql-query, hibernate throws an exception as below --
Code:
Invalid column name: lookup
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getColumnOrdinal(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at org.hibernate.type.CharacterType.get(CharacterType.java:23)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1690)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:991)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:942)
at org.hibernate.loader.Loader.getRow(Loader.java:855)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
The obvious reason is the query does not have 'lookup' column in projection. So how do I configure hibernate mapping in such a way that it will set only the sql projection columns into corresponding mapping class. I read
http://www.hibernate.org/hib_docs/v3/reference/en/html/performance.html#performance-fetching-lazyproperties but lazy=true, didnt solve problem either.
Please help!!
Regards
Nilesh