Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# leecook 3/4/2007 4:17 PM
Hey All,

I'm on my first adventure wih Nhibernate. I'm trying to write a custom Module but im getting a strange error I cant track down.

The code im calling is:

System.Collections.IList result = session.Find("select pc.parentCategory from ProductCategory pc");


The exception is:

{"in expected: pc [select pc.parentCategory from ProductCategory pc]"}
[NHibernate.QueryException]: {"in expected: pc [select pc.parentCategory from ProductCategory pc]"}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "in expected: pc [select pc.parentCategory from ProductCategory pc]"
Source: "NHibernate"
StackTrace: " at NHibernate.Hql.FromParser.Token(String token, QueryTranslator q)\r\n at NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q)\r\n at NHibernate.Hql.PreprocessingParser.End(QueryTranslator q)\r\n at NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q)\r\n at NHibernate.Hql.QueryTranslator.Compile()\r\n at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar)\r\n at NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow)\r\n at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)\r\n at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)\r\n at NHibernate.Impl.SessionImpl.Find(String query, Object[] values, IType[] types)\r\n at NHibernate.Impl.SessionImpl.Find(String query)\r\n at Castle.Facilities.NHibernateIntegration.SessionDelegate.Find(String query)\r\n at Cuyahoga.Modules.Ecommer
ce.CatalogueModule.GetSubCategories(Int32 node)\r\n at Cuyahoga.Modules.Ecommerce.Web.CatNav.Page_Load(Object sender, EventArgs e)"
TargetSite: {Void Token(System.String, NHibernate.Hql.QueryTranslator)}


Can someone throw me a clue?

Cheers,

lee
# martijnb 3/5/2007 2:10 AM
It looks like the ProductCategory is not mapped correctly. Usually when you get the error message with 'in expected' it indicates that you class is not mapped correctly (did you set as an embedded resource, btw?)
# leecook 3/5/2007 3:43 AM
Cheers. Worked a treat. Just had to embeded the mapping file.
# leecook 3/6/2007 4:25 AM
Hi people,

Another issue I cant quite understand.

Im getting the following error's .


This is my code:

IQuery sqlQuery = session.CreateSQLQuery("select {p.*} from ProductCategory {p}", "p", typeof(Cuyahoga.Modules.ECommerce.Domain.ProductCategory));
IList cats = sqlQuery.List();

When I step through it and look at the contents of sqlQuery, I get this: 'sqlQuery.ReturnTypes[0].ReturnedClass.DeclaringMethod' threw an exception of type 'System.InvalidOperationException' , in the returned class/ declaring method bit. And then {"Method may only be called on a Type for which Type.IsGenericParameter is true."} as the base exception.


I have used this code in another solution and it works fine.

Some other random details:

class CatalogueViewService : ModuleBase, ICatalogueViewService, INHibernateModule is the class declaration

I have embedded the the ProductCategory class

Cheers,

lee
# martijnb 3/6/2007 4:33 AM
I'd recommend to only use CreateSqlQuery in situations where hql can't do the job anymore.

Your query in hql:
IQuery query = session.CreateQuery("from ProductCategory");
IList cats = query.List();

You see, much cleaner :)
# leecook 3/6/2007 4:40 AM
complaining about the old 'in expected' with your code...which would suggest a mapping issue again but the xml file is embedded.