-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with Filter
PostPosted: Tue Apr 01, 2008 4:17 pm 
Newbie

Joined: Thu Jul 19, 2007 2:46 pm
Posts: 12
Good night

I am having a problem to enable a filter name GrupoTargetAtual declared in the hbm file GrupoTarget.hbm.xml pasted bellow


------------------------------///Grupo.hbm.xml///--------------------------------
<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" />
</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>

</hibernate-mapping>
------------------------------///Grupo.hbm.xml///--------------------------------


---------------------------///GrupoTarget.hbm.xml///---------------------------
<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" />

<filter name="GrupoTargetAtual"
condition=":dataGrupoTarget BETWEEN GPTG_DATAINICIO and GPTG_DATAFIM"/>

</class>

<filter-def name="GrupoTargetAtual">
<filter-param name="dataGrupoTarget" type="date"/>
</filter-def>

</hibernate-mapping>

---------------------------///GrupoTarget.hbm.xml///---------------------------
When i execute the command

session.EnableFilter("GrupoAtual").SetParameter("dataGrupo", DateTime.Now);

session.EnableFilter("GrupoTargetAtual").SetParameter("dataGrupoTarget", DateTime.Now);

grupos = session.CreateQuery("from Grupo").List<Grupo>();

session.DisableFilter("GrupoAtual");

session.DisableFilter("GrupoTargetAtual");

the filter GrupoTargetAtual is ignored by hibernate and i get all the values associated with the grupo in the table GrupoTarget, i just want the files whith a valid datarange

my solution to this was the code bellow

session.EnableFilter("GrupoAtual").SetParameter("dataGrupo", DateTime.Now);

grupos = session.CreateQuery("from Grupo").List<Grupo>();

session.DisableFilter("GrupoAtual");

foreach (Grupo grupo in grupos)
{
session.EnableFilter("GrupoTargetAtual").SetParameter("dataGrupoTarget", DateTime.Now);

IList<GrupoTarget> grupoTargets;

grupoTargets = session.CreateQuery("from GrupoTarget grupoTarget " +
"where grupoTarget.GrupoTargetkey.Grupo.Grupokey.CodigoGrupo = :grupoid " +
"and grupoTarget.GrupoTargetkey.Grupo.Grupokey.DataInicio = :grupoData")
.SetInt32("grupoid", grupo.Grupokey.CodigoGrupo)
.SetDateTime("grupoData", grupo.Grupokey.DataInicio).List<GrupoTarget>();

session.DisableFilter("GrupoTargetAtual");

grupo.GrupoTarget.Clear();

foreach (GrupoTarget grupoTarget in grupoTargets)
{
grupo.GrupoTarget.Add(grupoTarget);

}

But i think i am in the wrong way, someone could help me to find a better solution for my problem?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 2:12 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
A filter in the class mapping is not used for collection fetching. But yuo can also set a filter inside the collection mapping:

Code:
<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>

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.