-->
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.  [ 4 posts ] 
Author Message
 Post subject: ICriterion with related entites
PostPosted: Thu Nov 30, 2006 7:35 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
Im having trouble using ICriterion.

I have a DirectoryEntry entity that that a many to one relationship with a Location entity.

I want to return all DirectoryEntrys that have profile property or a relationship with a Location who's description property contains a search term.

Iv tried this:


Code:
ICriterion[] parameters = { Expression.Or(Expression.Like("Profile", search, MatchMode.Anywhere), Expression.Like("Location.Description", search, MatchMode.Anywhere)) };


But got this exception:

Code:
{"could not resolve property: Location.Description of: careers.core.domain.intdir.DirectoryEntry"}



How do i query the Description on the Location?


Mappings:

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>


    <property column="ClientID" type="Int32" name="Clientid" not-null="true" />
    <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"  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 = ? or de.Profile = ?) </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.Location,careers.core" lazy="false" table="Location">

    <id name="HesaId" column="HESA_id" type="Int32" unsaved-value="0">
      <generator class="assigned"/>
    </id>

    <property column="description" type="String" name="Description" length="255" />

  </class>

  <query name="Location.GetAll">from Location order by Description</query>
  <query name="Location.GetAllUsed">select distinct de.Location from DirectoryEntry de</query>

</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 1:10 pm 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
I would be very grateful if anyone could help me with this. I apologize if it as a dumb question or if i am taking the wrong approach.

I know i could use a named query such as

Code:
<query name="DirectoryEntry.Search">from DirectoryEntry de where de.Client.ClientName like ? or de.Profile like ?</query>


but this does not scale, as i am planning to search on many properties so i cant create a named query for every combination of properties, also when i try to run this query the nhibernate framework seems to stall on this piece of code in the Nhibernate framework:


QueryImpl.cs
Code:
#if NET_2_0
      public override IList<T> List<T>()
      {
         VerifyParameters();
         IDictionary namedParams = NamedParams;
         Before();
         try
         {
            return Session.Find<T>(BindParameterLists(namedParams), GetQueryParameters(namedParams));
         }
         finally
         {
            After();
         }
      }
#endif


Top
 Profile  
 
 Post subject: Re: ICriterion with related entites
PostPosted: Mon Dec 04, 2006 6:18 am 
Beginner
Beginner

Joined: Fri Jul 29, 2005 10:34 am
Posts: 25
bosh wrote:
Im having trouble using ICriterion.
Code:
{"could not resolve property: Location.Description of: careers.core.domain.intdir.DirectoryEntry"}

[/code]


Bosh,

For a criterion to be able to resolve "nested properties" you need to add a CreateCriteria() to your criteria. This is very important to understand since an ICriteria can "redefine" the scope of the relations (you programmatically must decide if you include a relation or not ) configured in your xml.

So before doing the .List() make sure you add (for example)
CreateCriteria("Location","Location", outerjoin )

Sebastian Talamoni


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 6:46 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
That did the trick!

Thanks very much for taking the time to answer.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.