-->
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: How can I select many property from many diffirent classes?
PostPosted: Sun May 04, 2008 9:19 pm 
Newbie

Joined: Thu Mar 27, 2008 10:35 pm
Posts: 4
Location: VN
i'd like to do this query by using Nhibernate : select productname,categoryname,companyname from products p, categories c , suppliers s where s.supplierid=s.supplierid and p.categoryid=c.categoryid. ( it's an ansi SQL query ). I'd like to select many properties from many diffirent presistent classes. Can i use ICriteria?

How can I do this?

This is the mapping file.

// product.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NorthwindCS" assembly="NorthwindCS">
<class name="Product" table="Products" lazy ="0">
<id name="ProductID" column="ProductID">
<generator class="increment"/>
</id>
<property name="ProductName" column="ProductName"/>
<property name="QuantityPerUnit" column="QuantityPerUnit"/>
<property name="UnitPrice" column="UnitPrice"/>
<property name="UnitsInStock" column="UnitsInStock"/>
<property name="UnitsOnOrder" column="UnitsOnOrder"/>
<property name="ReorderLevel" column="ReorderLevel"/>
<property name="Discontinued" column="Discontinued"/>
<property name ="SupplierID" column ="SupplierID"/>
<property name="CategoryID" column="CategoryID"/>
<many-to-one name="Supplier" column="SupplierID" class="Supplier"/>
<many-to-one name="Category" column="CategoryID" class="Category"/>
</class>
</hibernate-mapping>


//category.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NorthwindCS" assembly="NorthwindCS">
<class name="Category" table ="Categories" lazy ="0">
<id name="CategoryID" column ="CategoryID">
<generator class="increment"/>
</id>
<property name="CategoryName" column="CategoryName"/>
<property name="Description" column="Description"/>
<property name="Picture" column="Picture"/>
<bag name="Products" lazy ="0">
<key column="CategoryID"/>
<one-to-many class ="Product"/>
</bag>
</class>
</hibernate-mapping>

// supplier.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NorthwindCS" assembly="NorthwindCS">
<class name="Supplier" table="Suppliers" lazy ="0">
<id name="SupplierID" column="SupplierID">
<generator class="increment"/>
</id>
<property name="CompanyName" column="CompanyName"/>
<property name="ContactName" column="ContactName"/>
<property name="ContactTitle" column="ContactTitle"/>
<property name="Address" column="Address"/>
<property name="City" column="City"/>
<property name="Region" column="Region"/>
<property name="PostalCode" column="PostalCode"/>
<property name="Country" column="Country"/>
<property name="Phone" column="Phone"/>
<property name="Fax" column="Fax"/>
<property name="Homepage" column="Homepage"/>
<bag name="Products">
<key column="SupplierID"/>
<one-to-many class ="Product"/>
</bag>
</class>
</hibernate-mapping>

_________________
JC


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.