-->
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.  [ 5 posts ] 
Author Message
 Post subject: Only ID property available in Criteria
PostPosted: Mon Jan 02, 2006 10:10 pm 
Newbie

Joined: Mon Jan 02, 2006 9:57 pm
Posts: 7
Is there a situation where the ID is available for use in a criteria but other properties are not?

This works:
session.CreateCriteria(typeof(Move)).Add(Expression.Eq("Actor.Id", 1)).List();

This does not:
session.CreateCriteria(typeof(Move)).Add(Expression.Eq("Actor.Name", "Alphonse")).List();

Here is a snippet from Actor.hbm.xml (I removed properties for brevity):
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SR.Tactics.Actor, TacticsDAL" table="actors">
<id name="Id" column="id" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property column="name" type="String" name="Name" not-null="true" length="20" />
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 10:15 pm 
Newbie

Joined: Wed Oct 12, 2005 10:28 pm
Posts: 10
for you to add expression to another entity properties using Criteria you need to use CreateAlias or CreateCriteria API


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 11:32 pm 
Newbie

Joined: Mon Jan 02, 2006 9:57 pm
Posts: 7
I'm not sure what you mean. What is CreateCriteria API?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 12:42 am 
Newbie

Joined: Wed Oct 12, 2005 10:28 pm
Posts: 10
you can using something like this

ICriteria c = s.OpenSession().CreateCriteria(typeof(Product));
c.CreateAlias("Type","t");
c.CreateAlias("t.Color","c");
c.CreateAlias("c.Location","l");
c.Add(NHibernate.Expression.Expression.Eq("t.Name","Computer"));


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 5:32 pm 
Newbie

Joined: Mon Jan 02, 2006 9:57 pm
Posts: 7
Thanks ryzam. That worked well.


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