Hibernate version: 1.0.3
Name and version of the database you are using: Ms SQL Server 2000
Hi, I cant use a composite-id object, nHibernate returns the following error. I am not altering any id of the object, just returning the objects from the DataBase.
Quote:
{"identifier of an instance of ControleMobiliario.DP.InscricaoMobiliaria altered from ControleCorporativo.ControleGeral.DP.InscricaoCadastralPK (ControleCorporativo.ControleGeral.DP.InscricaoCadastralPK) to ControleCorporativo.ControleGeral.DP.InscricaoCadastralPK (ControleCorporativo.ControleGeral.DP.InscricaoCadastralPK)" }
Mapping File
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="PMV_DP" namespace="ControleCorporativo.ControleGeral.DP">
<class name="InscricaoCadastral" table="Geral_InscricaoCadastral" discriminator-value="0">
<composite-id name="Id" class="InscricaoCadastralPK">
<key-property name="Inscricao" column="inscricaoCadastral"/>
<key-property name="TipoInscricao" column="tipoInscricao"/>
</composite-id>
<discriminator column="TipoInscricao" type="Int64" insert="false"/>
</class>
</hibernate-mapping>
Class FileCode:
using System;
using Nullables;
using Utilitario.GerenciaDados;
using ControleCorporativo.ControleEndereco.DP;
using System.Collections;
namespace ControleCorporativo.ControleGeral.DP
{
/// <summary>
/// Summary description for InscricaoCadastral.
/// </summary>
public class InscricaoCadastral
{
#region Constructor
public InscricaoCadastral()
{
}
#endregion
#region Class Identifier
private InscricaoCadastralPK id;
public InscricaoCadastralPK Id
{
get { return this.id; }
set { this.id = value; }
}
#endregion
}
}
ID Class FileCode:
using System;
namespace ControleCorporativo.ControleGeral.DP
{
/// <summary>
/// Summary description for InscricaoCadastralPK.
/// </summary>
public class InscricaoCadastralPK
{
public InscricaoCadastralPK()
{
}
#region identificadores da classe
private long inscricao;
public virtual long Inscricao
{
get { return this.inscricao; }
set { this.inscricao = value; }
}
private long tipoInscricao;
public virtual long TipoInscricao
{
get { return this.tipoInscricao;}
set { this.tipoInscricao = value;}
}
#endregion
public override bool Equals(object obj)
{
InscricaoCadastralPK inscricaoCadastral = obj as InscricaoCadastralPK;
if (inscricaoCadastral == null )
{
return false;
}
return base.Equals( (this.tipoInscricao == inscricaoCadastral.TipoInscricao) &&
(this.inscricao == inscricaoCadastral.Inscricao) );
}
public override int GetHashCode()
{
string strCode = this.tipoInscricao.ToString() + this.inscricao.ToString();
return strCode.GetHashCode();
}
}
}
Class usage - How I am using it Code:
StringBuilder strHql = new StringBuilder();
strHql.Append(" select distinct m from InscricaoMobiliaria m ");
strHql.Append(" inner join m.relAtividadesExercidas a ");
strHql.Append(" where getdate() >= a.Id.DataInicioAtividade and ");
strHql.Append(" m.Id.TipoInscricao = 1 and ");
strHql.Append(" ( a.dataTerminoAtividade is null OR getdate() <= a.dataTerminoAtividade ) ");
IList lstInscricoes = session.Find(strHql.ToString());
Can anyone tell me what I am doing wrong ??