-->
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.  [ 2 posts ] 
Author Message
 Post subject: HOw to use join in CreateQuery
PostPosted: Wed Jun 10, 2009 5:01 am 
Newbie

Joined: Wed Jun 10, 2009 4:33 am
Posts: 1
hi everyone,
I am new in nhibernate and I want use join in a one-to-many(customer--order) relation:
---
ISession vSession= NHibernateSessionManager.Instance.GetSession();
string hql="from Customer c,Order o where c.customerID=o.customerID";
vSession.CreateQuery(hql).List<object[]>();
---

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="BasicSample.Core.Domain.Customer, BasicSample.Core" table="Customers">
<id name="ID" column="CustomerID">
<generator class="identity" />
</id>

<property name="CompanyName" column="CompanyName" />
<property name="ContactName" column="ContactName" />

<bag name="Orders" table="Orders" inverse="true">
<key column="CustomerID" />
<one-to-many class="BasicSample.Core.Domain.Order, BasicSample.Core" />
</bag>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="BasicSample.Core.Domain.Order, BasicSample.Core" table="Orders" >
<id name="ID" column="OrderID" unsaved-value="0">
<generator class="identity" />
</id>

<property name="OrderDate" column="OrderDate" />
<property name="ShipToName" column="ShipName" />

<many-to-one name="OrderedBy" column="CustomerID"
class="BasicSample.Core.Domain.Customer, BasicSample.Core" not-null="true" />
</class>
</hibernate-mapping>
---
and the error is "NHibernate.QueryException : could not resolve property", when i chang the hql to "from Customer ,Order " it works fine.

How did this happen and how can i use join in hql? can someone help me? Thank you.


Top
 Profile  
 
 Post subject: Re: HOw to use join in CreateQuery
PostPosted: Mon Jun 15, 2009 1:31 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
select c from Customer c join c.Orders o ....

http://nhforge.org/doc/nh/en/index.html#queryhql-joins

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.