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: