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.  [ 1 post ] 
Author Message
 Post subject: Mapping two table to one class X insert record
PostPosted: Tue Feb 10, 2009 8:05 am 
Newbie

Joined: Mon Feb 09, 2009 7:02 pm
Posts: 2
Hi i hope someone can answer me this.

I'm mapping two tables to one class using the JOIN statement.

I don't know if it's the best method to do that, but for me its the best fit, cause im working on a legacy database with some one-to-one relations.

Everything works fine if i try to load this entity class.

But when i try to insert a record on the database using this same class, it gives me an error, something about the SQLParameters index out of bounds.

I'm wondering if i am doing something wrong or if its just impossible to use this approch.

My situation is:

NHibernate version: 2.0.1.4000

Mapping documents:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="DAL.Base_Link, DAL" table="base_hierarquia">
    <id name="HierarquiaId" column="hierarquiaId" type="Guid">
      <generator class="assigned" />
    </id>
    <property name="HierarquiaSupId" column="hierarquiaSupId" type="Guid" />
    <property name="Instancia" column="Instancia" type="String" length="60"/>
    <property name="Nome" column="nome" type="String" length="255"/>
    <property name="Descricao" column="descricao" type="String" length="500"/>
    <property name="Ordem" column="ordem" type="Int16"/>
    <property name="CodigoHierarquico" column="codigoHierarquico" type="String"/>
    <many-to-one name="HierarquiaPai" class="DAL.Base_Hierarquia, DAL">
      <column name="hierarquiaSupId" />
    </many-to-one>
    <join table="base_link">
      <key column="linkId" />
      <property name="Url" column="url" type="String" length="500"/>
      <property name="Alvo" column="alvo" type="Guid" />
      <property name="Local" column="local" type="String" length="60"/>
      <property name="ExibirNoMenu" column="exibirNoMenu" type="Boolean"/>
      <property name="ExibirNoMapa" column="exibirNoMapa" type="Boolean"/>
      <property name="AtivarSeguranca" column="ativarSeguranca" type="Boolean"/>
      <property name="Tipo" column="tipo" type="Int16"/>
    </join>
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
            ITransaction transaction = session.BeginTransaction();
            try {
                Base_Link bli = new Base_Link();
                bli.HierarquiaId = Guid.NewGuid();
                bli.HierarquiaSupId = new Guid("ae3061eb-cdd9-4f76-89cc-66a6bbf77e45");
                bli.Instancia = "site";
                bli.Nome = "teste nhibernate";
                bli.Descricao = "tesde de descriçao";
                bli.Ordem = 2;
                bli.CodigoHierarquico = "00010001";
                bli.AtivarSeguranca = false;
                bli.ExibirNoMapa = true;
                bli.ExibirNoMenu = true;
                bli.Url = "http://www.google.com.br";
                bli.Tipo = 2;
                bli.Local = "home";

                // Tell NHibernate that this object should be saved
                session.Save(bli);

                // commit all of the changes to the DB and close the ISession
               [b] transaction.Commit();[/b] <-- Error on this line
               
            } catch (NHibernate.HibernateException ex) {
                transaction.Rollback();
                return;
            } finnaly {
                session.Close();
            }


Name and version of the database you are using: SQL Server 2005

Thanks.
Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.