-->
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: find by composite-id: throws exception
PostPosted: Fri Apr 28, 2006 4:06 pm 
Regular
Regular

Joined: Fri Jul 29, 2005 9:46 am
Posts: 101
Hi!

It seems that I can not find an object with a composite-id using the composite-id:

oe.Session.CreateQuery("from " + TypeName() + " as " + DefaultAlias() +" where " + DefaultAlias() + "." + PrimaryKeyName +" = :id");

if my type has a primary key, and I try to search an object using a composite-id object... i get an exception...

The problem seems to be in PathExpressionParser.cs around line 509 (it seems that this is plain not supported... it seems that the only workaround is to decompose the HQL to manually look for each of the components of the composite-id... i was wondering if there is some other way... and if it is not... perhaps this is fixed in the latest code in the SVN repository?):


public string WhereColumn
{
get
{
if( columns.Length != 1 )
{
throw new QueryException( "path expression ends in a composite value" );
}
return columns[ 0 ];
}
}



NHibernate version:1.02

Full stack trace of any exception that occurs:

Xade.BusinessObjects.FactoryOperationException: path expression ends in a composite value [from Corona.BusinessObjects.GrupoTarea as grupotarea where grupotarea.id = :id]

at Xade.BusinessObjects.BasePONOFactory`2.ExecuteWithResults[TCustomType](OperationEventHandler`1 operationHandler) in BasePONOFactory.cs:line 92
at Xade.BusinessObjects.BasePONOFactory`2.ExecuteSingleResult(OperationEventHandler`1 operationHandler) in BasePONOFactory.cs:line 61
at Xade.BusinessObjects.BasePONOFactory`2.Find(TIdType id) in BasePONOFactory.cs:line 136
at NUnit.Corona.BusinessObjects.TestGrupo.TestCrearGrupoConTarea() in TestGrupo.cs:line 42

NHibernate.QueryException: path expression ends in a composite value [from Corona.BusinessObjects.GrupoTarea as grupotarea where grupotarea.id = :id]

at NHibernate.Hql.PathExpressionParser.get_WhereColumn() in PathExpressionParser.cs:line 515
at NHibernate.Hql.WhereParser.DoPathExpression(String token, QueryTranslator q) in WhereParser.cs:line 422
at NHibernate.Hql.WhereParser.DoToken(String token, QueryTranslator q) in WhereParser.cs:line 440
at NHibernate.Hql.WhereParser.Token(String token, QueryTranslator q) in WhereParser.cs:line 281
at NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q) in D:\Documents and Settings\fperedo\My Documents\OpenSource\Nhibernate\src\NHibernate\Hql\ClauseParser.cs:line 103
at NHibernate.Hql.PreprocessingParser.Token(String token, QueryTranslator q) in PreprocessingParser.cs:line 146
at NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q) in D:\Documents and Settings\fperedo\My Documents\OpenSource\Nhibernate\src\NHibernate\Hql\ParserHelper.cs:line 32
at NHibernate.Hql.QueryTranslator.Compile() in D:\Documents and Settings\fperedo\My Documents\OpenSource\Nhibernate\src\NHibernate\Hql\QueryTranslator.cs:line 137
at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar) in D:\Documents and Settings\fperedo\My Documents\OpenSource\Nhibernate\src\NHibernate\Hql\QueryTranslator.cs:line 115
at NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow) in D:\Documents and Settings\fperedo\My Documents\OpenSource\Nhibernate\src\NHibernate\Impl\SessionFactoryImpl.cs:line 443
at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar) in D:\Documents and Settings\fperedo\My Documents\OpenSource\Nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1773
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) in D:\Documents and Settings\fperedo\My Documents\OpenSource\Nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1735
at NHibernate.Impl.QueryImpl.List() in D:\Documents and Settings\fperedo\My Documents\OpenSource\Nhibernate\src\NHibernate\Impl\QueryImpl.cs:line 27
at Xade.BusinessObjects.BasePONOFactory`2.FindOneWith(IQuery query) in BasePONOFactory.cs:line 141
at Xade.BusinessObjects.BasePONOFactory`2.<>c__DisplayClass7.b__6(Object sender, OperationEventArgs`1 oe) in BasePONOFactory.cs:line 134
at Xade.BusinessObjects.BasePONOFactory`2.ExecuteWithResults[TCustomType](OperationEventHandler`1 operationHandler) in BasePONOFactory.cs:line 81


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 4:31 pm 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
Hum...

I'm using the following query without problems:

Code:
// List all objects of the type "type" and use or not the Infos.EmpId
public static IList List(Type type, bool useEmpId)
{
     ISession session = null;
     try
     {
          session = NHibernateHelper.OpenSession();

          string hql = "FROM " + type + " AS obj";
          if (useEmpId)
               hql += " WHERE obj.EmpId = " + Infos.EmpId;

          IQuery query = session.CreateQuery(hql);
          return query.List();
     }
     finally
     {
          NHibernateHelper.CloseSession(session);
     }
}


As you can see, it will generate an hql query with or without all fields from composite-id.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 8:42 pm 
Regular
Regular

Joined: Fri Jul 29, 2005 9:46 am
Posts: 101
Hi! Thanks for you answer
I find it really strange that it works in for you...
After looking at your code I noticed something, you are not using parameters, you concatenate the hql string with your composite id:

Quote:
string hql = "FROM " + type + " AS obj";
if (useEmpId)
hql += " WHERE obj.EmpId = " + Infos.EmpId;


But I use parameters (in this case ":id"):

Quote:
oe.Session.CreateQuery("from " + TypeName() + " as " + DefaultAlias() +" where " + DefaultAlias() + "." + PrimaryKeyName +" = :id");
oe.Session.SetParameter("id",someId);



I dont understand why it works for you... IMO your code shoud concatenate the "ToString()" of your composite-id class with the HQL... did you write you ToString() in a special way so that this kind of queries are possible?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 30, 2006 12:18 pm 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
luxspes wrote:
Hi! Thanks for you answer
I find it really strange that it works in for you...
After looking at your code I noticed something, you are not using parameters, you concatenate the hql string with your composite id:

Quote:
string hql = "FROM " + type + " AS obj";
if (useEmpId)
hql += " WHERE obj.EmpId = " + Infos.EmpId;


But I use parameters (in this case ":id"):

Quote:
oe.Session.CreateQuery("from " + TypeName() + " as " + DefaultAlias() +" where " + DefaultAlias() + "." + PrimaryKeyName +" = :id");
oe.Session.SetParameter("id",someId);



I dont understand why it works for you... IMO your code shoud concatenate the "ToString()" of your composite-id class with the HQL... did you write you ToString() in a special way so that this kind of queries are possible?


What's the meaning of "IMO"? :P

I didn't write a new ToString().

Did you try my way (without :id)?

Bye


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.