Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
When I try to load an object with a composite id using a custom SQL query, I get an org.hibernate.QueryException. No exception is generated if I substitute an <id>.
Note that this a reporting object, i.e. does not exist in the database. This problem is similar to HHH-260 (
http://opensource.atlassian.com/project ... se/HHH-260).
This looks like a bug, but I'm hoping that either I've overlooked something or that
someone knows of a work around.
Thanks, Brian.
Hibernate version:
3.1.2
Mapping documents:
<hibernate-mapping>
<class name="com.timestock.tess.data.objects.DefectTypeReportData" mutable="false">
<composite-id>
<key-property name="defectType" type="java.lang.Short"/>
<key-property name="defectName" type="java.lang.String"/>
</composite-id>
<property name="userGroupId" type="java.lang.Long"/>
<property name="tranSetId" type="java.lang.Long"/>
<property name="tranSetGroupId" type="java.lang.Long"/>
<property name="areaX1" type="java.lang.Integer"/>
<property name="areaY1" type="java.lang.Integer"/>
<property name="areaX2" type="java.lang.Integer"/>
<property name="areaY2" type="java.lang.Integer"/>
<property name="defects" type="java.lang.Integer"/>
<property name="percent" type="java.lang.Double"></property>
<property name="cumPercent" type="java.lang.Double"></property>
<property name="itemName" type="java.lang.String"/>
<property name="tranSetName" type="java.lang.String"/>
<property name="tranSetGroupName" type="java.lang.String"/>
<property name="userGroupName" type="java.lang.String"/>
<property name="link" type="java.lang.String"/>
<property name="toolTip" type="java.lang.String"/>
<property name="softDelete" type="java.lang.Boolean"/>
</class>
<sql-query name="DefectTypeDefectComparisonReportDataQuery">
<return alias="pfr" class="com.timestock.tess.data.objects.DefectReportData"/>
<![CDATA[
SELECT dd.ts_type AS {pfr.defectType},
dd.ts_name AS {pfr.defectName},
MIN(ts.ts_id) AS {pfr.tranSetId},
MIN(ts.ts_name) AS {pfr.tranSetName},
dd.ts_soft_delete AS {pfr.softDelete},
sum(d.ts_defect_count) AS {pfr.defects},
-1 AS {pfr.percent},
-1 AS {pfr.cumPercent},
-1 AS {pfr.areaX1},
-1 AS {pfr.areaY1},
-1 AS {pfr.areaX2},
-1 AS {pfr.areaY2},
MIN(tsg.ts_id) AS {pfr.tranSetGroupId},
MIN(tsg.ts_name) AS {pfr.tranSetGroupName},
0 AS {pfr.userGroupId},
CAST('All' AS VARCHAR) AS {pfr.userGroupName},
CAST('' AS VARCHAR) AS {pfr.link},
CAST('' AS VARCHAR) AS {pfr.toolTip}
FROM ts_defects_interval d
JOIN ts_transets ts on ts.ts_id = d.ts_transet_id
JOIN ts_defect_defs dd on dd.ts_id = d.ts_defect_def_id
JOIN ts_transetgroup_transets_map tm on tm.ts_transet_incarnation_id = d.ts_transet_incarnation_id
JOIN ts_transet_groups tsg on tsg.ts_id = tm.ts_transet_group_id
JOIN ts_usergroup_users_map um on um.ts_user_incarnation_id = d.ts_user_incarnation_id
JOIN ts_user_groups ug on ug.ts_id = um.ts_usergroup_id
WHERE d.ts_occur_date >= :startDate AND d.ts_occur_date <= :endDate
AND (0 = :tsg_id OR tsg.ts_id = :tsg_id) AND (0 = :ts_id OR ts.ts_id = :ts_id)
AND 0 = :tu_id AND (0 = :ug_id OR ug.ts_id = :ug_id)
GROUP BY dd.ts_type, dd.ts_name, dd.ts_soft_delete
]]>
</sql-query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
2006-05-05 12:40:35,278 ERROR [org.hibernate.impl.SessionFactoryImpl] - <Error in named query: DefectTypeDefectComparisonReportDataQuery>
org.hibernate.QueryException: No column name found for property [defectType] for alias [pfr] [SELECT dd.ts_type AS {pfr.defectType},
dd.ts_name AS {pfr.defectName},
MIN(ts.ts_id) AS {pfr.tranSetId},
MIN(ts.ts_name) AS {pfr.tranSetName},
dd.ts_soft_delete AS {pfr.softDelete},
sum(d.ts_defect_count) AS {pfr.defects},
-1 AS {pfr.percent},
-1 AS {pfr.cumPercent},
-1 AS {pfr.areaX1},
-1 AS {pfr.areaY1},
-1 AS {pfr.areaX2},
-1 AS {pfr.areaY2},
MIN(tsg.ts_id) AS {pfr.tranSetGroupId},
MIN(tsg.ts_name) AS {pfr.tranSetGroupName},
0 AS {pfr.userGroupId},
CAST('All' AS VARCHAR) AS {pfr.userGroupName},
CAST('' AS VARCHAR) AS {pfr.link},
CAST('' AS VARCHAR) AS {pfr.toolTip}
FROM ts_defects_interval d
JOIN ts_transets ts on ts.ts_id = d.ts_transet_id
JOIN ts_defect_defs dd on dd.ts_id = d.ts_defect_def_id
JOIN ts_transetgroup_transets_map tm on tm.ts_transet_incarnation_id = d.ts_transet_incarnation_id
JOIN ts_transet_groups tsg on tsg.ts_id = tm.ts_transet_group_id
JOIN ts_usergroup_users_map um on um.ts_user_incarnation_id = d.ts_user_incarnation_id
JOIN ts_user_groups ug on ug.ts_id = um.ts_usergroup_id
WHERE d.ts_occur_date >= :startDate AND d.ts_occur_date <= :endDate
AND (0 = :tsg_id OR tsg.ts_id = :tsg_id) AND (0 = :ts_id OR ts.ts_id = :ts_id)
AND 0 = :tu_id AND (0 = :ug_id OR ug.ts_id = :ug_id)
GROUP BY dd.ts_type, dd.ts_name, dd.ts_soft_delete]
at org.hibernate.loader.custom.SQLQueryParser.resolveProperties(SQLQueryParser.java:262)
at org.hibernate.loader.custom.SQLQueryParser.substituteBrackets(SQLQueryParser.java:149)
at org.hibernate.loader.custom.SQLQueryParser.process(SQLQueryParser.java:85)
at org.hibernate.loader.custom.SQLCustomQuery.<init>(SQLCustomQuery.java:157)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:21)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:113)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:409)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:327)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:800)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:726)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:269)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:320)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3637)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4073)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:909)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:872)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1106)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1019)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1011)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:440)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
Name and version of the database you are using:
postgres 8.1.2
The generated SQL (show_sql=true):
see above
Debug level Hibernate log excerpt: