Good Morning,
I am having a problem whith filters in my nhibernate application, the problem is that some filters dont get activated when nhibernate loads the result, a class named 'Estimativa' dont get this effective date filter activated for no aparente reason, i review all the hbm´s and classes and apparently everthing is fine
Someone Can help me in solve this problem please
When i try to get the object 'TAREFA' I need to get the only the values fo the object 'ESTIMATIVA' that is in the range for the effective date filter defined in hbm
I try to solve this in hql, but the result that i get running the sql generated in the query analyzer, and in the system is different, something is really wrong here
Here is the hbm´s files
-----------------------------------//Tarefa//------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2"
namespace="ProducaoMidiaMix.Negocio" assembly="ProducaoMidiaMix">
<class name="Tarefa" table="SPMM_TAREFA">
<composite-id name="Tarefakey" class="ProducaoMidiaMix.Negocio.Tarefa+TarefaKey, ProducaoMidiaMix" unsaved-value="none" access="property">
<key-property name="CodigoTarefa" type="System.Int32" column="TAREFA_COD" />
<key-property name="DataInicio" type="System.DateTime" column="TAREFA_DATAINICIO" />
</composite-id>
<property name="DataFim" type="System.DateTime" column="TAREFA_DATAFIM" not-null="false" />
<property name="NomeTarefa" type="System.String" column="TAREFA_NOME" not-null="true" length="100" />
<property name="Usuario" type="System.String" column="USUARIO_NOME" not-null="true" />
<many-to-one name="ConfiguracaoPraca" class="ProducaoMidiaMix.Negocio.ConfiguracaoPraca, ProducaoMidiaMix" fetch="select">
<column name="CONFIGPRACA_COD" not-null="true" />
<column name="CONFIGPRACA_DATAINICIO" not-null="true" />
</many-to-one>
<many-to-one name="Processo" class="ProducaoMidiaMix.Negocio.Processo, ProducaoMidiaMix" fetch="select">
<column name="PROCESSO_COD" not-null="true" />
<column name="PROCESSO_DATAINICIO" not-null="true" />
</many-to-one>
<many-to-one name="GrupoPonderacao" class="ProducaoMidiaMix.Negocio.Grupo, ProducaoMidiaMix" fetch="select">
<column name="GRUPO_PONDERACAO" not-null="true" />
<column name="GRUPO_DATAINICIOPONDERACAO" not-null="true" />
</many-to-one>
<many-to-one name="GrupoExportacao" class="ProducaoMidiaMix.Negocio.Grupo, ProducaoMidiaMix" fetch="select">
<column name="GRUPO_EXPORTACAO" not-null="true" />
<column name="GRUPO_DATAINICIOEXPORTACAO" not-null="true" />
</many-to-one>
<filter name="TarefaAtual"
condition=":dataTarefa BETWEEN TAREFA_DATAINICIO and TAREFA_DATAFIM"/>
</class>
<filter-def name="TarefaAtual">
<filter-param name="dataTarefa" type="date"/>
</filter-def>
</hibernate-mapping>
The object associated whith Tarefa that is grupo
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="ProducaoMidiaMix.Negocio.Grupo, ProducaoMidiaMix" table="SPMM_GRUPO">
<composite-id name="Grupokey" class="ProducaoMidiaMix.Negocio.Grupo+GrupoKey, ProducaoMidiaMix" unsaved-value="none" access="property">
<key-property name="CodigoGrupo" type="System.Int32" column="GRUPO_COD" />
<key-property name="DataInicio" type="System.DateTime" column="GRUPO_DATAINICIO" />
</composite-id>
<property name="DataFim" type="System.DateTime" column="GRUPO_DATAFIM" not-null="false" />
<property name="NomeGrupo" type="System.String" column="GRUPO_NOME" not-null="false" />
<property name="Usuario" type="System.String" column="USUARIO_NOME" not-null="false" length="100" />
<bag name="TarefaPonderacao" inverse="true" lazy="false" cascade="none">
<key>
<column name="GRUPO_PONDERACAO" not-null="true" />
<column name="GRUPO_DATAINICIOPONDERACAO" not-null="true" />
</key>
<one-to-many class="ProducaoMidiaMix.Negocio.Tarefa, ProducaoMidiaMix" />
</bag>
<bag name="TarefaExportacao" inverse="true" lazy="false" cascade="none">
<key>
<column name="GRUPO_DATAINICIOEXPORTACAO" not-null="true" />
<column name="GRUPO_EXPORTACAO" not-null="true" />
</key>
<one-to-many class="ProducaoMidiaMix.Negocio.Tarefa, ProducaoMidiaMix" />
</bag>
<bag name="GrupoTarget" inverse="true" lazy="false" cascade="none" fetch="select">
<key>
<column name="GRUPO_COD" not-null="true" />
<column name="GRUPO_DATAINICIO" not-null="true" />
</key>
<one-to-many class="ProducaoMidiaMix.Negocio.GrupoTarget, ProducaoMidiaMix" />
<filter name="GrupoTargetAtual" condition=":dataGrupoTarget BETWEEN GPTG_DATAINICIO and GPTG_DATAFIM"/>
</bag>
<filter name="GrupoAtual"
condition=":dataGrupo BETWEEN GRUPO_DATAINICIO and GRUPO_DATAFIM"/>
</class>
<filter-def name="GrupoAtual">
<filter-param name="dataGrupo" type="date"/>
</filter-def>
<filter-def name="GrupoTargetAtual">
<filter-param name="dataGrupoTarget" type="date"/>
</filter-def>
</hibernate-mapping>
the object that associate GRUPO and TARGET
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="ProducaoMidiaMix.Negocio.GrupoTarget, ProducaoMidiaMix" table="SPMM_GRUPOTARGET">
<composite-id name="GrupoTargetkey" class="ProducaoMidiaMix.Negocio.GrupoTarget+GrupoTargetKey, ProducaoMidiaMix" unsaved-value="none" access="property">
<key-property name="DataInicio" type="System.DateTime" column="GPTG_DATAINICIO" />
<key-many-to-one name="Grupo" class="ProducaoMidiaMix.Negocio.Grupo, ProducaoMidiaMix">
<column name="GRUPO_COD" />
<column name="GRUPO_DATAINICIO" />
</key-many-to-one>
<key-many-to-one name="Target" class="ProducaoMidiaMix.Negocio.Target, ProducaoMidiaMix" >
<column name="TARGET_COD" />
<column name="TARGET_DATAINICIO" />
</key-many-to-one>
</composite-id>
<property name="DataFim" type="System.DateTime" column="GPTG_DATAFIM" not-null="true" />
</class>
</hibernate-mapping>
the object target
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="ProducaoMidiaMix.Negocio.Target, ProducaoMidiaMix" table="SPMM_TARGET">
<composite-id name="Targetkey" class="ProducaoMidiaMix.Negocio.Target+TargetKey, ProducaoMidiaMix" unsaved-value="none" access="property">
<key-property name="CodigoTarget" type="System.Int32" column="TARGET_COD" />
<key-property name="DataInicio" type="System.DateTime" column="TARGET_DATAINICIO" />
</composite-id>
<property name="DataFim" type="System.DateTime" column="TARGET_DATAFIM" not-null="true" />
<property name="NomeTarget" type="System.String" column="TARGET_NOME" not-null="true" length="100" />
<property name="Usuario" type="System.String" column="USUARIO_NOME" not-null="true" length="100" />
<bag name="GrupoTarget" inverse="true" lazy="false" cascade="none">
<key>
<column name="TARGET_COD" not-null="true" />
<column name="TARGET_DATAINICIO" not-null="true" />
</key>
<one-to-many class="ProducaoMidiaMix.Negocio.GrupoTarget, ProducaoMidiaMix" />
</bag>
<bag name="TargetCaracteristicaDetalhe" inverse="true" lazy="false" cascade="none">
<key>
<column name="TARGET_COD" not-null="true" />
<column name="TARGET_DATAINICIO" not-null="true" />
</key>
<one-to-many class="ProducaoMidiaMix.Negocio.TargetCaracteristicaDetalhe, ProducaoMidiaMix" />
</bag>
<bag name="Estimativa" inverse="true" lazy="true" cascade="none">
<key>
<column name="TARGET_COD" not-null="true" />
<column name="TARGET_DATAINICIO" not-null="true" />
</key>
<one-to-many class="ProducaoMidiaMix.Negocio.Estimativa, ProducaoMidiaMix" />
<filter name="EstimativaAtualTarget" condition=":dataEstimativa BETWEEN ESTIMATIVA_DATAINICIAL and ESTIAMTIVA_DATAFINAL"/>
</bag>
<filter name="TargetAtual"
condition=":dataTarget BETWEEN TARGET_DATAINICIO and TARGET_DATAFIM"/>
</class>
<filter-def name="TargetAtual">
<filter-param name="dataTarget" type="date"/>
</filter-def>
<filter-def name="EstimativaAtualTarget">
<filter-param name="dataEstimativa" type="date"/>
</filter-def>
</hibernate-mapping>
and the object that i can´t activated the effective date filter, ESTIMATIVA
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="ProducaoMidiaMix.Negocio.Estimativa, ProducaoMidiaMix" table="SPMM_ESTIMATIVA">
<composite-id name="Estimativakey" class="ProducaoMidiaMix.Negocio.Estimativa+EstimativaKey, ProducaoMidiaMix" unsaved-value="none" access="property">
<key-property name="DataInicio" type="System.DateTime" column="ESTIMATIVA_DATAINICIAL" />
<key-many-to-one name="Target" class="ProducaoMidiaMix.Negocio.Target, ProducaoMidiaMix" >
<column name="TARGET_COD" />
<column name="TARGET_DATAINICIO" />
</key-many-to-one>
<key-many-to-one name="IbopePraca" class="ProducaoMidiaMix.Negocio.IbopePraca, ProducaoMidiaMix">
<column name="COD_UNIDADE_NEGOCIO" />
<column name="COD_PRACA" />
</key-many-to-one>
</composite-id>
<property name="DataFim" type="System.DateTime" column="ESTIAMTIVA_DATAFINAL" not-null="false" />
<property name="Valor" type="System.Int32" column="ESTIMATIVA_VALOR" not-null="false" />
<property name="Usuario" type="System.String" column="USUARIO_NOME" not-null="true" length="100" />
<filter name="EstimativaAtual"
condition=":dataEstimativa BETWEEN ESTIMATIVA_DATAINICIAL and ESTIAMTIVA_DATAFINAL"/>
</class>
<filter-def name="EstimativaAtual">
<filter-param name="dataEstimativa" type="date"/>
</filter-def>
</hibernate-mapping>
I try to make the hql to get this filter to work
tarefas = session.CreateQuery("select t from Tarefa t " +
"inner join t.GrupoPonderacao.GrupoTarget as gt " +
"inner join t.GrupoExportacao.GrupoTarget as gte " +
"inner join gt.GrupoTargetkey.Target as tar " +
"inner join tar.Estimativa as est " +
"Where :data between t.Tarefakey.DataInicio and t.DataFim " +
"and :data between t.GrupoPonderacao.Grupokey.DataInicio and t.GrupoPonderacao.DataFim " +
"and :data between t.GrupoExportacao.Grupokey.DataInicio and t.GrupoExportacao.DataFim " +
"and :data between t.Processo.Processokey.DataInicio and t.Processo.DataFim " +
"and :data between t.ConfiguracaoPraca.ConfiguracaoPracakey.DataInicio and t.ConfiguracaoPraca.DataFim " +
"and :data between gt.GrupoTargetkey.DataInicio and gt.DataFim " +
"and :data between gte.GrupoTargetkey.DataInicio and gt.DataFim " +
"and :data between tar.Targetkey.DataInicio and tar.DataFim " +
"and :data between est.Estimativakey.DataInicio and est.DataFim ")
.SetParameter("data", DateTime.Now)
.List<Tarefa>();
the sql generated by that is this one
select tarefa0_.TAREFA_COD as TAREFA1_8_,
tarefa0_.TAREFA_DATAINICIO as TAREFA2_8_,
tarefa0_.TAREFA_DATAFIM as TAREFA3_8_,
tarefa0_.TAREFA_NOME as TAREFA4_8_,
tarefa0_.USUARIO_NOME as USUARIO5_8_,
tarefa0_.CONFIGPRACA_COD as CONFIGPR6_8_,
tarefa0_.CONFIGPRACA_DATAINICIO as CONFIGPR7_8_,
tarefa0_.PROCESSO_COD as PROCESSO8_8_,
tarefa0_.PROCESSO_DATAINICIO as PROCESSO9_8_,
tarefa0_.GRUPO_PONDERACAO as GRUPO10_8_,
tarefa0_.GRUPO_DATAINICIOPONDERACAO as GRUPO11_8_,
tarefa0_.GRUPO_EXPORTACAO as GRUPO12_8_,
tarefa0_.GRUPO_DATAINICIOEXPORTACAO as GRUPO13_8_
from SPMM_TAREFA tarefa0_
inner join SPMM_GRUPO grupo1_ on
tarefa0_.GRUPO_PONDERACAO=grupo1_.GRUPO_COD
and tarefa0_.GRUPO_DATAINICIOPONDERACAO=grupo1_.GRUPO_DATAINICIO
inner join SPMM_GRUPOTARGET grupotarge2_ on
grupo1_.GRUPO_COD=grupotarge2_.GRUPO_COD
and grupo1_.GRUPO_DATAINICIO=grupotarge2_.GRUPO_DATAINICIO
inner join SPMM_GRUPO grupo3_ on
tarefa0_.GRUPO_EXPORTACAO=grupo3_.GRUPO_COD
and tarefa0_.GRUPO_DATAINICIOEXPORTACAO=grupo3_.GRUPO_DATAINICIO
inner join SPMM_GRUPOTARGET grupotarge4_ on
grupo3_.GRUPO_COD=grupotarge4_.GRUPO_COD
and grupo3_.GRUPO_DATAINICIO=grupotarge4_.GRUPO_DATAINICIO
inner join SPMM_TARGET target5_ on
grupotarge2_.TARGET_COD=target5_.TARGET_COD
and grupotarge2_.TARGET_DATAINICIO=target5_.TARGET_DATAINICIO
inner join SPMM_ESTIMATIVA estimativa6_ on
target5_.TARGET_COD=estimativa6_.TARGET_COD and
target5_.TARGET_DATAINICIO=estimativa6_.TARGET_DATAINICIO,
SPMM_PROCESSO processo7_,
SPMM_CONFIGURACAOPRACA configurac8_
where (getdate() between tarefa0_.TAREFA_DATAINICIO and tarefa0_.TAREFA_DATAFIM )
and(getdate() between grupo1_.GRUPO_DATAINICIO and grupo1_.GRUPO_DATAFIM )
and(getdate() between grupo3_.GRUPO_DATAINICIO and grupo3_.GRUPO_DATAFIM )
and(getdate() between tarefa0_.PROCESSO_DATAINICIO and processo7_.PROCESSO_DATAFIM
and tarefa0_.PROCESSO_COD=processo7_.PROCESSO_COD
and tarefa0_.PROCESSO_DATAINICIO=processo7_.PROCESSO_DATAINICIO)
and(getdate() between tarefa0_.CONFIGPRACA_DATAINICIO and configurac8_.CONFIGPRACA_DATAFIM
and tarefa0_.CONFIGPRACA_COD=configurac8_.CONFIGPRACA_COD
and tarefa0_.CONFIGPRACA_DATAINICIO=configurac8_.CONFIGPRACA_DATAINICIO)
and(getdate() between grupotarge2_.GPTG_DATAINICIO and grupotarge2_.GPTG_DATAFIM )
and(getdate() between grupotarge4_.GPTG_DATAINICIO and grupotarge2_.GPTG_DATAFIM )
and(getdate() between target5_.TARGET_DATAINICIO and target5_.TARGET_DATAFIM )
and(getdate() between estimativa6_.ESTIMATIVA_DATAINICIAL and estimativa6_.ESTIAMTIVA_DATAFINAL )
the result in the query Analyzer is correct but in the program the filter doesnt work,
getdate() between estimativa6_.ESTIMATIVA_DATAINICIAL and estimativa6_.ESTIAMTIVA_DATAFINAL )
why this is happen, please someone colud help me???
|