views:

253

answers:

0

Hi All

I'm attempting to use an HQL query in a <loader> element to load an entity based on other entities.

My class is as follows

public class ParentOnly
{
    public ParentOnly(){}
    public virtual int Id { get; set; }
    public virtual string ParentObjectName { get; set; }
}

and the mapping looks like this

<class name="ParentOnly">
  <id name="Id">
    <generator class="identity" />
  </id>
  <property name="ParentObjectName" />
  <loader query-ref="parentonly"/>
</class>

<query name="parentonly" >
  select new ParentOnly() 
  from SimpleParentObject as spo
  where spo.Id = :id
</query>

The class that I am attemping to map on top of is SimpleParentObject, which has its own mapping and can be loaded and saved without problems.

When I call session.Get<ParentOnly>(id) the sql runs correctly against the SimpleParentObject table, and a ParentOnly object is instantiated (as I can step through the constructer), but only a null comes back, rather than the instantiated ParentOnly object.

I can do this succesfully using a instead of the HQL, but am trying to build this in a database independent fashion.

Any thoughts on how to get the <loader> and <query> elements to return a populated ParentOnly object...?

Thanks

Matt