ADO Exception in HQL query

Posted by Yoav on Stack Overflow See other posts from Stack Overflow or by Yoav
Published on 2011-01-15T10:06:18Z Indexed on 2011/01/15 13:53 UTC
Read the original article Hit count: 239

Filed under:
|

I have 2 classes: Project and DataStructure. Class Project contains member List<DataStructure>. My goal is to load a Project and all its DataStructures in one call.

public class Project
{
    public virtual string Id { get { } set { } }
    public virtual string Name { get { } set { } }
    public virtual ISet<DataStructure> DataStructures { get { } set { } }
}

public class DataStructure
{
    public virtual string Id { get { } set { } }
    public virtual string Name { get { } set { } }
    public virtual string Description { get { } set { } }
    public virtual Project Project { get { } set { } }
    public virtual IList<DataField> Fields { get { } set { } }
}

Note that DataStructure also contains a list of class DataField but I don’t want to load these right now.

Mapping in Fluent NHibernate:

public class ProjectMap : ClassMap<Project>
{
    public ProjectMap()
    {
        Table("PROJECTS");
        Id(x => x.Pk, "PK");
        Map(x => x.Id, "ID");
        Map(x => x.Name, "NAME");
        HasMany<DataStructure>(x => x.DataStructures).KeyColumn("FK_PROJECT");
    }
}

public class DataStructureMap : ClassMap<DataStructure>
{
    public DataStructureMap()
    {
        Table("DATA_STRUCTURES");
        Map(x => x.Id, "ID");
        Map(x => x.Name, "NAME");
        Map(x => x.Description, "DESCRIPTION");
        References<Project>(x => x.Project, "FK_PROJECT");
        HasMany<DataField>(x => x.Fields).KeyColumn("FK_DATA_STRUCTURE");
    }
}

This is my query:

using (ISession session = SessionFactory.OpenSession())
{
    IQuery query = session.CreateQuery("from Project pr left join pr.DataStructure");
    project = query.List<Project>();
}

query.List() returns this exception:

NHibernate.Exceptions.GenericADOException: Could not execute query[SQL: SQL not available] ---> System.ArgumentException: The value "System.Object[]" is not of type "Project" and cannot be used in this generic collection.

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about hql