-->
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: Problem with Criteria Query
PostPosted: Wed Jun 14, 2006 5:25 am 
Newbie

Joined: Mon Apr 10, 2006 11:59 am
Posts: 9
Hibernate version:
I'm using NHibernate version 1.0.2

Code between sessionFactory.openSession() and session.close():
NH.ICriteria criteria = GetSession().CreateCriteria(typeof(CheckPresentation));
then I try to perform this query:
criteria.Add(NH.Expression.Expression.Eq("Batch.Submitter.Branch.BranchCode", BranchCode));
Then I get the exception bellow.
The question is, can I perform such a query with NHibernate, or I need
to do other operations, before I perform this query ?
Full stack trace of any exception that occurs:
NHibernate.QueryException: could not resolve property:Batch.Submitter.Branch.BranchCode of :Datacomp.PaymentMeans.DataAccess.Model.CheckPresentation
at NHibernate.Persister.AbstractPropertyMapping.ToColumns(String alias, String propertyName)
at NHibernate.Expression.AbstractCriterion.GetColumns(ISessionFactoryImplementor factory, Type persistentClass, String property, String alias, IDictionary aliasClasses)
at NHibernate.Expression.SimpleExpression.ToSqlString(ISessionFactoryImplementor factory, Type persistentClass, String alias, IDictionary aliasClasses)
at NHibernate.Loader.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl criteria)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)
at NHibernate.Impl.CriteriaImpl.List()
at Datacomp.PaymentMeans.DataAccess.NHibernate.CheckPresentationNHibernateDAO.FindByCriteria(String DateBegin, String DateEnd, String BranchCode) in C:\work\MeiosPagamento\Iteration2\Telecompensacao\src\PaymentMeans\Datacomp.PaymentMeans.DataAccess\NHibernate\CheckPresentationNHibernateDAO.cs:line 271
at Datacomp.PaymentMeans.AdministrationApplication.Business.CheckPresentationBLL.GetChecksByDateBranch(String dateBegin, String dateEnd, String branchCode) in C:\work\MeiosPagamento\Iteration2\Telecompensacao\src\PaymentMeans\AdministrationApplication\Datacomp.PaymentMeans.AdministrationApplication\Business\CheckPresentationBLL.cs:line 298

Name and version of the database you are using:
I'm using sql server 2005

Thanks in advance for your help.

Luis


Top
 Profile  
 
 Post subject: Re: Problem with Criteria Query
PostPosted: Wed Jun 14, 2006 7:18 am 
Newbie

Joined: Mon Jun 05, 2006 8:51 am
Posts: 18
luis.filipe wrote:
Code:
NH.ICriteria criteria = GetSession().CreateCriteria(typeof(CheckPresentation));
// then I try to perform this query:
criteria.Add(NH.Expression.Expression.Eq("Batch.Submitter.Branch.BranchCode", BranchCode));

The thing is that Criteria API supports dot notation only when querying components. So if either of Submitter or Branch parts is an association, you'll either have to rewrite your query in HQL or use nested criteria.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 9:31 am 
Newbie

Joined: Mon Apr 10, 2006 11:59 am
Posts: 9
Hi,
thank you for your answer.
Submitter is a component, however Branch is part of an Association.
Do you have a link to a good example of Nested Criteria ?
The one that we have on the NHibernate documentation is very simple and the explanation isn't very detailed.

Thanks in advance

Luis


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 11:10 am 
Newbie

Joined: Mon Apr 10, 2006 11:59 am
Posts: 9
Hi again.

I solved my problem using something like this:

criteria.CreateCriteria("Batch", "batch").Add(NH.Expression.Expression.Eq("Submitter.Branch.Id", Convert.ToInt32(BranchCode)));

I tried a couple of times, and when I finally understood it, it worked as expected. Hope this can helps someone out there.

Regards

Luis


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.