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: Need Help in using Joins...Mapping File.
PostPosted: Thu Dec 28, 2006 3:18 am 
Newbie

Joined: Mon Dec 18, 2006 9:49 am
Posts: 2
Location: hyderabad
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?


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.