Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# pedro 5/27/2008 10:58 PM (edited 5/28/2008 3:24 AM)
Hi, i develop module and Show error when acces hql.

in expected: A [from Actividades A where A.SeccionId.Id =:sectionId]

I need help...

Public Actividades GetAllActiv()
{
ISession session = this._sessionManager.OpenSession();
string hql = "from Actividades A where A.SeccionId.Id =:sectionId";
IQuery q = session.CreateQuery(hql);
q.SetInt32("SeccionId", base.Section.Id);

Actividades act;


try
{
act = (Actividades)q.UniqueResult(); ///// error ---> in expected: A [from Actividades A where A.SeccionId.Id =:sectionId]
}
catch
{
act = null;
}
return act;
}

******************************************************************************
IQuery query = session.CreateQuery("from Actividades f");
IList cats = query.List();

******************************************************************************

in expected: f [from Actividades f]
Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código.

Detalles de la excepción: NHibernate.QueryException: in expected: f [from Actividades f]

Error de código fuente:

Se ha generado una excepción no controlada durante la ejecución de la solicitud Web actual. La información sobre el origen y la ubicación de la excepción pueden identificarse utilizando la excepción del seguimiento de la pila siguiente.

Seguimiento de la pila:


[QueryException: in expected: f [from Actividades f]]
NHibernate.Hql.Classic.FromParser.Token(String token, QueryTranslator q) +1770
NHibernate.Hql.Classic.ClauseParser.Token(String token, QueryTranslator q) +1119
NHibernate.Hql.Classic.PreprocessingParser.End(QueryTranslator q) +66
NHibernate.Hql.Classic.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q) +307
NHibernate.Hql.Classic.QueryTranslator.Compile() +162
NHibernate.Hql.Classic.QueryTranslator.Compile(IDictionary replacements, Boolean scalar) +84
NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow, IDictionary enabledFilters) +253
NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar) +76
NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results) +190
NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) +70
NHibernate.Impl.QueryImpl.List() +135
Cuyahoga.Modules.Agenda.AgendaModule.GetAllActivity() +107
Cuyahoga.Modules.Agenda.Web.AdminAgenda.Page_Load(Object sender, EventArgs e) +212
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436




any idea???

HELP ME..... PLEASE.!!!!
# martijnb 5/28/2008 11:26 AM
Does your module implement INHibernateModule? This is required to have classes automatically being added to the NH confiduration.
# pedro 5/28/2008 4:22 PM (edited 5/28/2008 4:30 PM)
hello Martijnb, not how to implement the module INHibernateModule, I could show an example?

this is my class:


using.....
.
.
.



namespace Cuyahoga.Modules.Agenda
{
[Transactional]
public class AgendaModule : ModuleBase, INHibernateModule
{

#region Member Variables
private ISessionManager _sessionManager;
#endregion


#region Constructor

public AgendaModule(ISessionManager sessionmanager)
{
this._sessionManager = sessionmanager;

}

#endregion

public IList GetAllActivity()
{

ISession session = this._sessionManager.OpenSession();

//string hql = "from Actividades f where f.Section.Id = :sectionid";
//IQuery q = session.CreateQuery(hql);
//q.SetInt32("sectionid", base.Section.Id);

IQuery query = session.CreateQuery("from Actividades f");
IList cats = query.List();

try
{
// return q.List();
return cats;

}
catch(Exception ex)
{
throw new Exception("Unable to get Files for section: " + base.Section.Title, ex);
}

}


#endregion

#region CurrentViewControlPath

public override string CurrentViewControlPath
{
get
{
string basePath = "Modules/Agenda/";
return basePath + "Agenda.ascx";

}
}
#endregion


//#region IActionProvider Members

//ActionCollection IActionProvider.GetOutboundActions()
//{
// throw new Exception("The method or operation is not implemented.");
//}

//#endregion









}
}
# martijnb 5/28/2008 5:01 PM
That looks fine.
Maybe you have an error in the NHibernate mapping files? Is the build action of the mapping files set to Content?
# pedro 5/28/2008 5:11 PM
this is my class Actividades:

using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using Cuyahoga.Core.Domain;
using Cuyahoga.Web.UI;
using System.Security.Principal;
using System.Collections;

namespace Cuyahoga.Modules.Agenda.Domain
{

public class Actividades
{
#region Constructor
public Actividades()
{
}
#endregion

#region Variables

private int _Id;
private Section _Section;

#endregion

#region Propiedades

public virtual int Id
{
get { return this._Id; }
set { this._Id = value; }
}

public virtual Section Section
{
get { return this._Section; }
set { this._Section = value; }
}


public virtual IList AllowedRoles
{
get { return this._allowedRoles; }
set { this._allowedRoles = value; }
}

#endregion


#region Equals And HashCode Overrides

public override bool Equals(object obj)
{
if (this == obj) return true;
if ((obj == null) || (obj.GetType() != this.GetType())) return false;
Actividades castObj = (Actividades)obj;
return (castObj != null) &&
this._Id == castObj.Id;
}

public override int GetHashCode()
{
int hash = 57;
hash = 27 * hash * _Id.GetHashCode();
return hash;
}
#endregion

public virtual bool IsDownloadAllowed(Role roleToCheck)
{
foreach (Role role in this._allowedRoles)
{
if (role.Id == roleToCheck.Id && role.Name == roleToCheck.Name)
{
return true;
}
}
return false;
}

public virtual bool IsDownloadAllowed(IIdentity userToCheck)
{
User cuyahogaUser = userToCheck as User;
if (cuyahogaUser == null)
{
return this.IsAnonymousDownloadAllowed();
}
else
{
foreach (Role role in cuyahogaUser.Roles)
{
if (IsDownloadAllowed(role))
{
return true;
}
}
return false;
}
}

public virtual bool IsAnonymousDownloadAllowed()
{
foreach (Role role in this._allowedRoles)
{
foreach (AccessLevel accessLevel in role.Permissions)
{
if (accessLevel == AccessLevel.Anonymous)
{
return true;
}
}
}
return false;
}

}
}
# pedro 5/28/2008 5:17 PM (edited 5/28/2008 5:47 PM)
this is the file mapping.

hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"

class name="Cuyahoga.Modules.Agenda.Domain.Actividades, Cuyahoga.Modules.Agenda" table="cm_Agenda_Actividades"

id name="Id" column="AgendaId" type="Int32" unsaved-value="-1"
generator class="native"
id

many-to-one name="Section" class="Cuyahoga.Core.Domain.Section, Cuyahoga.Core" column="sectionid" cascade="none"


class

hibernate-mapping



***********************

in the file mapping should be included in all fields on the table? or only those it deems necesrios ..






# pedro 5/28/2008 8:15 PM
Hey martijnb, i need help... please..
# martijnb 5/28/2008 9:25 PM
So far, everything looks correct. You don't need to map every column of the table.

Btw, I made a mistake: you have to set the build action of the .hbm.xml file to 'Embedded Resource' and to be sure, do a rebuild of the project.

If that doesn't work, turn on logging by uncommenting the log4net section in the web.config (you'll need at least the root logger, set to DEBUG).
[root]
    [priority value="DEBUG" /]
    [appender-ref ref="rollingFile" /]
[/root]

(replace square brackets with angled brackets)

After starting Cuyahoga, NHibernate logs which mapping files are loaded.
# pedro 5/29/2008 12:18 AM
ok martijnb, thank you for your help, try to generate a new project
to correct the root problem ..