-->
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.  [ 3 posts ] 
Author Message
 Post subject: Exception: could not insert
PostPosted: Sun Oct 23, 2005 3:32 pm 
Hi all,

I need help
I have two class UF and Cidade.

//UF
Code:
    public class UF
    {


        private int m_Id;
      private string m_UF;
        private string m_Descricao;
      
        public virtual  int Id
        {
            get
            {
                return m_Id;
            }
         set
         {
            m_Id=value;
         }
        }

      public virtual  string uf
      {
         get
         {
            return m_UF;
         }
         set
         {
            m_UF=value;
         }
      }

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


//Cidade
Code:
    public class Cidade
    {

      public Cidade()
      {
         m_UF=new UF();
      }

        private System.Int32 m_Id;
        private UF m_UF;
        private System.String m_Nome;

        public virtual System.Int32 Id
        {
            get
            {
                return m_Id;
            }
         set
         {
            m_Id=value;
         }
        }

        public virtual UF UF
        {
            get
            {
                return m_UF;
            }
            set
            {
                m_UF = value;
            }
        }

        public virtual System.String Nome
        {
            get
            {
                return m_Nome;
            }
            set
            {
                m_Nome = value;
            }
        }
    }



The hbm file.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" >
  <class name="RDestribBUS.UF, RDestribBUS" table="UF">
    <id name="Id" type="Int32" column="UFId">
      <generator class="native" />
    </id>
    <property name="uf" column="UF" type="String(2)" />
    <property name="Descricao" column="Descricao" type="String(40)" />
  </class>
</hibernate-mapping>



<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" >
  <class name="RDestribBUS.Cidade, RDestribBUS" table="Cidade">
    <id name="Id" type="Int32" column="CidadeId">
      <generator class="native" />
    </id>
    <one-to-one name="UF" class="RDestribBUS.UF, RDestribBUS"  />
    <property name="Nome" column="Nome" type="String(40)" />
  </class>
</hibernate-mapping>




The method
Code:
      public System.Boolean saveCidade(Cidade oCidade)
      {
         ITransaction tx;
         try
         {
            session=factory.OpenSession();
            tx=session.BeginTransaction();

            if (oCidade.Id ==0 )
               session.Save(oCidade);

            else
               session.Update(oCidade);

            tx.Commit();
            return true;
         }

         catch (Exception e)
         {
            Messages.Erro.SendMessage(e.Message,"Erro",e);
            return false;
         }
      }


Whem the method saveCidade is called the follow error is displayed
"could not insert: [RDestribBUS.Cidade]"

I dont know what to do....
can you help me? Please....


Top
  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 4:43 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Look for more details in the inner exception(s).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 10:11 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
To get the full exception, you can either change log4net priority to DEBUG or replace:
Code:
Messages.Erro.SendMessage(e.Message,"Erro",e);

by
Code:
Messages.Erro.SendMessage(e.ToString(),"Erro",e);


On side note, instead of doing
Code:
if (oCidade.Id ==0 )
    session.Save(oCidade);
else
    session.Update(oCidade);

You can simply call:
Code:
session.SaveOrUpdate(oCidade);

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.