-->
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.  [ 1 post ] 
Author Message
 Post subject: query.List() returning strange results for a joined subclass
PostPosted: Mon Sep 03, 2007 6:01 am 
Newbie

Joined: Mon Apr 03, 2006 5:12 pm
Posts: 15
Location: Glasgow, Scotland
Hibernate 1.2.0.4000

I have the following mapping where the Event object includes a joined subclass TrainingEvent:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="MyNamespace" assembly="MyAssembly">

    <class name="Event" table="Event">

        <id name="Id" unsaved-value="-9999">
            <column name="EvtId" sql-type="Int32" not-null="true" />
            <generator class="increment" />
        </id>

      <version name="VersionNumber" column="EvtVersionNo" type="Int32" access="property" />
       
        <property name="TypeCode" column="EvtTypeCd" />
        <property name="StartDateTime" column="EvtStartDateTime" />
        <property name="EndDateTime" column="EvtEndDateTime" />
        <property name="Deleted" column="EvtDeleteFl" />   
       
         <joined-subclass name="TrainingEvent" table="TrainingEvent">
         <key column="EvtId"/>
            <property name="Name" column="TevName"/>
            <property name="NullableTrainingProviderId" column="TpvId" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
         <property name="NullableLocation" column="TevLocation" />
         <property name="Completed" column="TevCompleteFl"/>
         <property name="TrainingCoursesAreRefreshers" column="TevCoursesAreRefreshers"/>
         
            <set name="TrainingCourseIds" table="TrainingEventCourse">
            <key column="EvtId"/>
            <element column="TcrId" type="Int32"/>
         </set>
         
         <set name="EmployeeIds" table="TrainingEventEmployee">
            <key column="EvtId"/>
            <element column="EmpId" type="Int32"/>
         </set>

      </joined-subclass> 
         
    </class>

</hibernate-mapping>


I have one row in the Event and TrainingEvent tables with the same EvtId as expected. I then use the following query to return Events in a certain date range:

Code:
string sql = "from TrainingEvent tev, Event evt where ( "
                         + " (:startDateTime < evt.StartDateTime AND :endDateTime > evt.EndDateTime) "
                         + " OR (:startDateTime BETWEEN evt.StartDateTime AND evt.EndDateTime) "
                         + " OR (:endDateTime BETWEEN evt.StartDateTime AND evt.EndDateTime) "
                         + " ) AND tev.Id = evt.Id ";
         
IQuery query = mySessionCreateQuery(sql);
query.SetDateTime("startDateTime", startDateTime);
query.SetDateTime("endDateTime", endDateTime);
IList results = query.List();


The SQL query NHibernate runs returns the one row as expected. (verified by using Profiler)
The object returned in the IList (results[0]) contains two objects:
{Length=2}
[0]: {MyNamespace.TrainingEvent}
[1]: {MyNamespace.TrainingEvent}

In other code results[0] would just return an object. Is this something to do with my joined subclass?


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

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.