Hi all,
I'm working on hibernate (version 3.1) on oracle. I have a problem using a named query. I am creating my hibernate mapping files by hand. The problem is as follows:
I have an object named DataPoint. It has it's own hibernate mapping as follows:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.mycomp.DataPoint"
table="RO_DATA_POINT"
dynamic-update="false"
dynamic-insert="false"
mutable="false"
>
<id
name="id"
column="ID"
type="int"
>
<generator class="assigned">
</generator>
</id>
<property
name="date"
type="com.mycomp.HibernateUTC$TimestampType"
update="true"
insert="true"
column="DATE_"
/>
<property
name="value"
type="double"
update="true"
insert="true"
column="VALUE"
/>
<many-to-one
name="archive"
class="com.mycomp.Archive"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ARCHIVE_ID"
/>
</class>
</hibernate-mapping>
I have a separate object that I want to be able to run a complex query and return the results as a list of DataPoint objects. However, the results only populate a subset of the datapoint values and i was hoping the others could be left as null.
I created a named query to do this
Code:
<sql-query name="getControlPointData">
<return alias="point" entity-name="DataPoint"/>
<![CDATA[
SELECT ds.date_ AS {point.date}, SUM(dst.value) AS {point.value} FROM ro_daily_summary ds, ro_daily_summary_total dst, ro_rep_data_source_ref ref, ro_rep_monitored_property_ref mp, ro_service_type_mapping stm, ro_data_source rds, ro_rep_reconciliation_point rec,
ro_rep_revenue_stream rev WHERE ds.id=dst.daily_summary_id AND stm.id=dst.service_type_mapping_id AND stm.id=mp.service_type_mapping_id AND ref.id=mp.data_source_ref_id AND ref.reconciliation_point_id=rec.id AND ref.data_source_id=rds.id AND
rec.revenue_stream_id=rev.id AND ds.data_source_id=rds.id AND rec.id=? AND ds.date_ BETWEEN (?) AND (?) GROUP BY ds.date_
]]>
</sql-query>
Hibernate didn't autopopulate the non used fields of DataPoint in my query and I get exceptions so I then tried to use an alias to the DataPoint with the values that I want only:
Code:
<class entity-name="SimpleDataPoint" name="com.mycomp.DataPoint">
<id name="date" type="com.mycomp.HibernateUTC$TimestampType" />
<property name="value" type="double" />
</class>
I then reference my alias "SimpleDataPoint" in my named query and everything works! ....
Except, now all my non-named queries which reference DataPoint are actually trying to use SimpleDataPoint!!!
It's as if my hibernate mapping for SimpleDataPoint is overwriting my DataPoint hibernate mapping!
any help at all is much appreciated.
thanks and regards,
Brian