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: Use of Expression with a many-to-many mapping
PostPosted: Mon Dec 11, 2006 8:12 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
Hibernate version: 1.2.0 beta 1

Mapping documents:

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>




I am having problems writing a query using the Expression class.

What i need to to return a list of 'DirectoryEntry' who have a relationship with a 'Tow' of a certain id. I dont understand how to query each Directory Entry's set of Tows?


Top
 Profile  
 
 Post subject: Re: Use of Expression with a many-to-many mapping
PostPosted: Mon Dec 11, 2006 8:49 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
bosh wrote:
I am having problems writing a query using the Expression class.

What i need to to return a list of 'DirectoryEntry' who have a relationship with a 'Tow' of a certain id. I dont understand how to query each Directory Entry's set of Tows?


First, don't use Expression class, see its javadoc :
Code:
/**
* This class is semi-deprecated. Use <tt>Restrictions</tt>.
*
* @see Restrictions
* @author Gavin King
*/

So, use Restrictions instead.

Then, with HQL, you must "think" object. So, you should not use columns, but property names.

Your HQL query would look like :
<query name="Two.GetAll">from Tow t where t.Towid > 1 order by t.TowDesc</query>

Hey, I just noticed I'm in the NHibernate forum. Maybe what I just said is not completely true, I use Hibernate :-).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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.