-->
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.  [ 3 posts ] 
Author Message
 Post subject: Trying to set criteria based on one side of many-to-one
PostPosted: Mon Sep 05, 2005 5:23 pm 
I have a Store object with a property of type Location. There is a many-to-one mapping between Store and Location based on zipcode. The following code:

Code:
criteria.Add(Expression.And(Expression.Between("Location.Latitude", radiusAssistant.MinLatitude, radiusAssistant.MaxLatitude),
Expression.Between("Location.Longitude", radiusAssistant.MinLongitude, radiusAssistant.MaxLongitude)));

return criteria.List();


Throws the error:

could not resolve property:Location.Latitude

However, a search on zip code works just fine like so:
Code:
criteria.Add(Expression.Eq("Location.ZipCode" zipcode);


My mapping files:

Store mapping:
Code:
    <many-to-one name="Location" column="zipcode" class="Store.Location, Store" />


Location mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class
    name="Store.Location, Store"
    table="ZipCode" >
    <id name="ZipCode" column="zipcode" type="String" unsaved-value="" access="nosetter.camelcase-underscore">
       <generator class="assigned" />
    </id>

    <property name="AreaCode" column="areacode" type="String"/>
    <property name="Latitude" column="latitude" type="Double"/>
    <property name="Longitude" column="longitude" type="Double"/>
   
  </class>
</hibernate-mapping>


Top
  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 4:22 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
I'm having a very similar issue, same error.

The criteria:

Code:
IList trans = s.CreateCriteria( typeof( Transaction ) )
    .Add( Expression.Eq( "Account.ID", account.ID ) )
    .Add( Expression.Eq( "Type.CollectedFlag", true ) ).List();


causes: could not resolve property:Type.CollectedFlag

(elided) mappings:

from Transaction:

Code:
<!-- references -->
<many-to-one name="Type" column="TypeCode" class="TBI.ngBO.Catalog.TransactionType" />
<many-to-one name="Account" column="AccountID" class="TBI.ngBO.Core.Account" />


from TransactionType:

Code:
<property name="CollectedFlag" type="Boolean" />


from Account (which works just fine):

Code:
<id name="ID" type="Int32" access="field.lowercase-underscore" unsaved-value="0">
   <generator class="identity"/>
</id>


Top
 Profile  
 
 Post subject: Criteria not really baked?
PostPosted: Tue Sep 06, 2005 4:36 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
I found http://nhibernate.sourceforge.net/forum/viewtopic.php?t=668 using different search criteria. Apparently what we're looking for isn't possible? The only reason the criteria expression worked on Account.ID (or Location.ZipCode in your case) was because that is the identifier, which CreateCriteria knows how to work with.

Back to HQL...[/url]


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