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?