hai guys,
nhibernate is really great work done by u.i am a learner in nhibernate. i cant able to get how to write the mapping file,for joins...(i have written a HQL query).i have read the mapping doc..and refererd the sites. but i am unable to solve it...so i need your help..please help me..
i want to get an output like the output of this query...
select p.parentID,p.parentname,c.name from Parent p,child c where p.parentID = c.parentID
parentID is primary key for Parent table,forien key for child table.
childID id the primay key for child
My MApping Files are:
Parent: (Parent.hbm.xml file)
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="WindowsApplication1.Parent, WindowsApplication1" table="Parent">
<id name="pID" column="parentID">
<generator class="identity"/>
</id>
<property name="parentname" column="parentname"/>
<one-to-many name="child" class="WindowsApplication1.child,WindowsApplication1" column="parentID"/>
</class>
</hibernate-mapping>
child:(child.hbm.xml file)
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="WindowsApplication1.child, WindowsApplication1" table="child">
<id name="cID" column="childID">
<generator class="identity"/>
</id>
<property name="name" column="name"/>
<property name="ParentID" column="parentID"/>
</class>
</hibernate-mapping>
My class files are:
public class Parent
{
private int m_parentid;
private string m_parentname;
public child m_child;
public int pID
{
get { return m_parentid; }
set { m_parentid = value; }
}
public string parentname
{
get { return m_parentname; }
set { m_parentname = value; }
}
public string name
{
get { return m_child.name; }
set { m_child.name = value; }
}
}
public class child
{
private int m_childid;
private string m_name;
private int m_parentid;
public int cID
{
get { return m_childid; }
set { m_childid = value; }
}
public string name
{
get { return m_name; }
set { m_name = value; }
}
public int ParentID
{
get { return m_parentid;}
set { m_parentid = value; }
}
}
and my Hql query is
from Parent p left join fetch p.Child c where p.pID = c.ParentID
iam getting an err as the element has invalid child element one-to-many
and i have tried
IList parent = sess.CreateCriteria(typeof(WindowsApplication1.Parent)).CreateCriteria("child").List();
also gettng the same error..
please help me...and let me know where is the probelm?
|