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: Trouble with session.Get
PostPosted: Wed Apr 16, 2008 1:49 pm 
Newbie

Joined: Wed Apr 16, 2008 1:20 pm
Posts: 16
Good Day,

I read a lot of tutorials around the internet and created some exemples in VS2005 + MSSQL2005, but im having some trouble im my example and i dont know what to do anymore. I made the .hbm files and implemented the classes. The inserting is doing fine but when i try to make the "CreateQuery" with the "where" clause or the .Get method. It gives me the message "could not execute query" and show a long sql query with some "?" (interrogation marks)

I'll post the classes and the .hbm files, if anyone could help me ill thanks a lot, im desespered.

SQL Tables:

Code:
dbo.tblPagamentoInss
-pgiCodigo (PK,char(4),not null)
- pdgiDescricao (varchar(255),null)

dbo.Inss
- insCodigo(PK,int,not null)
- insNome (varchar(30),null)
- insFpas (int,null)
- insCodigoTerceiros(int,null)
- insCodigoAcidenteTrabalho (char(9), null)
- insContribuicaoEmpresa (numeric (4,2), null)
- insAcidenteTrabalho (numeric (4,2),null)
- insTerceiros(numeric (4,2), null)
- insCodigoPgamentoInss (FK,char(4), not null)


CLASSES

Code:
public class Inss
    {

        public virtual int Codigo
        {get { return _codigo; } set { _codigo = value; }}

        public virtual string Nome
   {get { return _nome; }set { _nome = value; }}

        public virtual int FPas
   {get { return _fPas; }set { _fPas = value; }}


        public virtual int CodigoTerceiros
   {get { return _codigoTerceiros; }set { _codigoTerceiros = value;}}


        public virtual string CodigoAcidenteTrabalho
   {get { return _codigoAcidenteTrabalho;}set { _codigoAcidenteTrabalho = value; }}


        public virtual decimal ContribuicaoEmpresa
        {get { return _contribuicaoEmpresa; }set { _contribuicaoEmpresa = value; }}

        public virtual decimal AcidenteTrabalho
        {get { return _acidenteTrabalho; }set { _acidenteTrabalho = value; }}


        public virtual decimal Terceiros
        {get { return _terceiros; }set { _terceiros = value; }}

     
        public virtual PagamentoInss PagamentoInss
        {get { return _pagamentoInss; }set { _pagamentoInss = value; }}
         
    }


public class PagamentoInss
    {
        public virtual String Codigo
        {get { return _codigo; }set { _codigo = value; }}

        public virtual string Descricao
        {get { return _descricao; }set { _descricao = value; }}

        public virtual IList inssList
        {get{return _inssList;}set{_inssList=value;}}

        public virtual String DescricaoConcat
        {get { return Convert.ToString(this.Codigo) + " - " + this.Descricao; }}
    }


HBM FILES:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Entidades.Inss, Entidades" table="tblInss" lazy="true">
      <id name="Codigo" column="insCodigo" type="Int32">
         <generator class="increment"/>
      </id>
      <property name="Nome" column="insNome" not-null="true" type="String" />
      <property name="FPas" column="insFpas" type="Int32" />
      <property name="CodigoTerceiros" column="insCodigoTerceiros" type="Int32" />
      <property name="CodigoAcidenteTrabalho" column="insCodAcidenteTrabalho" type="String" />
      <property name="ContribuicaoEmpresa" column="insContribuicaoEmpresa" type="Decimal" />
      <property name="AcidenteTrabalho" column="insAcidenteTrabalho" type="Decimal" />
      <property name="Terceiros" column="insTerceiros" type="Decimal" />

      <many-to-one name="PagamentoInss" column="insCodigoPagamentoInss" not-null="true" fetch="join" cascade="save-update" />
   </class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Entidades.PagamentoInss,Entidades" table="tblPagamentoInss" lazy="true">
      
      <id name="Codigo" column="pgiCodigo" type="String">
         <generator class="increment"/>
      </id>

      <bag name="inssList" table="tblInss" cascade="all" fetch="join" inverse="true">
         <key column="PK_INSS" />
         <one-to-many class="Entidades.Inss,Entidades" />
      </bag>

      <property name="Descricao" column="pgiDescricao" type="String" />
   </class>
</hibernate-mapping>



NOW the problem:

When i do this works fine:
IQuery query = session.CreateQuery("From Inss");
return query.List();

when i do this DONT WORK!:
IQuery query = session.CreateQuery("From Inss where Nome=:name");
query.SetString("name", "sometext");

and gives me the error:
could not execute query (some sql query)

_________________
Weekend PLEASE!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 10:34 pm 
Newbie

Joined: Wed Jun 27, 2007 9:34 am
Posts: 8
Can you post the actual SQL query it is trying to execute?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 17, 2008 7:24 am 
Newbie

Joined: Wed Apr 16, 2008 1:20 pm
Posts: 16
Here it comes..

Code:
NHibernate.ADOException was unhandled by user code
  Message="could not execute query\r\n[ select inss0_.insCodigo as insCodigo1_, inss0_.insNome as insNome1_, inss0_.insFpas as insFpas1_, inss0_.insCodigoTerceiros as insCodig4_1_, inss0_.insCodAcidenteTrabalho as insCodAc5_1_, inss0_.insContribuicaoEmpresa as insContr6_1_, inss0_.insAcidenteTrabalho as insAcide7_1_, inss0_.insTerceiros as insTerce8_1_, inss0_.insCodigoPagamentoInss as insCodig9_1_ from tblInss inss0_ where (Nome=? ) ]\r\n  Name: name - Value: Teste\r\n[SQL: select inss0_.insCodigo as insCodigo1_, inss0_.insNome as insNome1_, inss0_.insFpas as insFpas1_, inss0_.insCodigoTerceiros as insCodig4_1_, inss0_.insCodAcidenteTrabalho as insCodAc5_1_, inss0_.insContribuicaoEmpresa as insContr6_1_, inss0_.insAcidenteTrabalho as insAcide7_1_, inss0_.insTerceiros as insTerce8_1_, inss0_.insCodigoPagamentoInss as insCodig9_1_ from tblInss inss0_ where (Nome=? )]"
  Source="NHibernate"
  StackTrace:
       em NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
       em NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
       em NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
       em NHibernate.Hql.Classic.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters)
       em NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results)
       em NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
       em NHibernate.Impl.QueryImpl.List()
       em AcessaDados.ADInss.Listar(String Nome) na C:\Projetos\Top Folha\1.Documentação\TopFolhaWeb\TopFolhaWeb\AcessaDados\ADInss.cs:linha 44
       em Negocios.Inss.listar(String Nome) na C:\Projetos\Top Folha\1.Documentação\TopFolhaWeb\TopFolhaWeb\Negocios\Inss.cs:linha 27
       em Apresentacao_Cadastros_INSS.Editar(String Descricao) na c:\Projetos\Top Folha\1.Documentação\TopFolhaWeb\TopFolhaWeb\Apresentacao\Cadastros\CadINSS.aspx.cs:linha 193
       em Apresentacao_Cadastros_INSS.GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) na c:\Projetos\Top Folha\1.Documentação\TopFolhaWeb\TopFolhaWeb\Apresentacao\Cadastros\CadINSS.aspx.cs:linha 173
       em System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e)
       em System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
       em System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e)
       em System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       em System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e)
       em System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       em System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e)
       em System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument)
       em System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       em System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       em System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       em System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

_________________
Weekend PLEASE!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 17, 2008 9:37 am 
Regular
Regular

Joined: Thu Mar 06, 2008 5:06 am
Posts: 68
Try to use an alias:

IQuery query = session.CreateQuery("From Inss inss where inss.Nome=:name");


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 17, 2008 9:38 am 
Newbie

Joined: Wed Jun 27, 2007 9:34 am
Posts: 8
It looks like in the table "tblInss" the column "insCodigoAcidenteTrabalho" is mapped to "insCodAcidenteTrabalho".


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.