-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Named Query Problem
PostPosted: Thu Jan 05, 2006 11:36 am 
Newbie

Joined: Thu Jan 06, 2005 6:49 am
Posts: 4
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 2:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you query for an entity using a native SQL query, you have to fully fill it. Use a scalar query if you want scalar values only.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.