I would like to select an attribute(applicationName) from a component object of a mapped class. Here is my mapping...
<class name="CommonLogEvent" mutable="false" table="UL_COMMON_LOG_EVENT" dynamic-update="false" dynamic-insert="false">
<cache usage="read-only"/>
<id name="id" column="cle_id" type="long">
<generator class="native"/>
</id>
<property name="observedTime" type="java.util.Date" update="true" insert="true" column="observed_time" not-null="false"/>
<property name="version" type="java.lang.String" update="true" insert="true" column="version"/>
<property name="situation" type="java.lang.String" update="true" insert="true" column="situation"/>
<property name="message" type="java.lang.String" update="true" insert="true" column="message"/>
<property name="status" type="java.lang.String" update="true" insert="true" column="status"/>
<property name="severity" type="java.lang.String" update="true" insert="true" column="severity"/>
<property name="logLevel" type="int" update="true" insert="true" column="log_level"/>
<component name="componentIdentification">
<property name="addressType" type="java.lang.String" update="true" insert="true" column="address_type"/>
<property name="addressName" type="java.lang.String" update="true" insert="true" column="address_name"/>
<property name="componentName" type="java.lang.String" update="true" insert="true" column="component_name"/>
<property name="applicationName" type="java.lang.String" update="true" insert="true" column="application_name"/>
<property name="instanceName" type="java.lang.String" update="true" insert="true" column="instance_name"/>
<property name="threadName" type="java.lang.String" update="true" insert="true" column="thread_name"/>
<property name="environmentName" type="java.lang.String" update="true" insert="true" column="environment_name"/>
</component>
I am trying this in my mapping file...
<sql-query name="selectDistinctAppNames">
<return alias="cle" class="CommonLogEvent"/>
select distinct {cle}.APPLICATION_NAME {cle.applicationName} from UL_COMMON_LOG_EVENT {cle}
</sql-query>
I get the following error because applicationName is not in CommonLogEvent, it is in ComponentIdentification, which is contained by CommonLogEvent.
net.sf.hibernate.QueryException: No column name found for property [applicationName] [
select distinct {cle}.APPLICATION_NAME {cle.applicationName} from UL_COMMON_LOG_EVENT {cle}
]
at net.sf.hibernate.loader.SQLLoader.substituteBrackets(SQLLoader.java:172)
at net.sf.hibernate.loader.SQLLoader.renderStatement(SQLLoader.java:85)
at net.sf.hibernate.loader.SQLLoader.<init>(SQLLoader.java:71)
at net.sf.hibernate.impl.SessionImpl.findBySQL(SessionImpl.java:3622)
at net.sf.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:52)
How do I reference a component within my mapped class? I tried this but got an error as well.
<sql-query name="selectDistinctAppNames">
<return alias="cle" class="CommonLogEvent"/>
select distinct {cle}.APPLICATION_NAME
{cle.componentIdentification.applicationName} from UL_COMMON_LOG_EVENT {cle}
</sql-query>
I saw a post about this earlier, however no resolution was posted.
http://forum.hibernate.org/viewtopic.ph ... t=sqlquery