-->
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: Help with querying entity relationships
PostPosted: Wed Jan 10, 2007 7:12 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
I can get my head around how to do this query with NHibernate.

I ideally need to take the ICriteron Object approach rather than them using named query's, because i want to combine the expression with other expressions.

I have 2 entities 'DirectoryEntry' and 'Tow', each DirectoryEntry can have a relationship with zero or more Tows.

What i need is an expression that returns all DirectoryEntrys who have a certain Tow. How do i query this relation ship?

Here are my mapping docs:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="careers.core.domain.intdir.DirectoryEntry,careers.core" lazy="false"  table="idInternationalDirectory">

    <id name="Id" column="ID" type="Int32" unsaved-value="0">
      <generator class="native"/>
    </id>
    <many-to-one name="Client"    class="careers.core.domain.cems.Client,careers.core" column="ClientID"/>
    <many-to-one name="Location"    class="careers.core.domain.intdir.Location,careers.core" column="HESAID"/>
    <property column="Profile" type="String" name="Profile" not-null="true" length="2000" />
    <property column="url" type="String" name="Url" not-null="true" length="50" />

    <set name="Tows" lazy="false"  table="idTowLookup">
      <key column="entryID" />
      <many-to-many column="TOWID" class="careers.core.domain.intdir.Tow,careers.core" />
    </set>

  </class>

  <query name="DirectoryEntry.Search">from DirectoryEntry de where de.Client.ClientName like ? or de.Profile like ?</query>
  <query name="DirectoryEntry.SearchByName">from DirectoryEntry de where de.Client.ClientName like ?</query>
  <query name="DirectoryEntry.SearchByProfile">from DirectoryEntry de where de.Profile like ?</query>
  <query name="DirectoryEntry.S">from DirectoryEntry de where de.Client.ClientName like ? or de.Profile like ?</query>
 
</hibernate-mapping>



Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="careers.core.domain.intdir.Tow,careers.core" lazy="false" table="csTOW">
    <id name="Towid" column="TOWID" type="Int32" unsaved-value="0">
      <generator class="native"/>
    </id>
    <property column="TOW_desc" type="String" name="TowDesc" length="250" />
    <property column="bitcode" type="Int32" name="Bitcode" />
  </class>

  <query name="Two.GetAll">from Tow where Towid > 1 order by TOW_desc</query>
</hibernate-mapping>


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.