Domanda

Considera il seguente file di mapping Hibernate:

<hibernate-mapping ...>
<class name="ContentPackage" table="contentPackages">
    <id name="Id" column="id" type="int"><generator class="native" /></id>
    ...
    <bag name="Clips" table="contentAudVidLinks">
      <key column="fk_contentPackageId"></key>
      <many-to-many class="Clip" column="fk_AudVidId"></many-to-many>
      <filter name="effectiveDate" condition=":asOfDate BETWEEN startDate and endDate"  />
    </bag>
</class>
</hibernate-mapping>

Quando eseguo il seguente comando:

  _session.EnableFilter("effectiveDate").SetParameter("asOfDate", DateTime.Today);

  IList<ContentPackage> items = _session.CreateCriteria(typeof(ContentPackage))
                                     .Add(Restrictions.Eq("Id", id))
                                     .List<ContentPackage>();

L'SQL risultante ha la clausola WHERE sulla tabella di mappatura intermedia (contentAudVidLinks), piuttosto che " Clips " tabella anche se ho aggiunto l'attributo filter al Bag of Clips.

Cosa sto sbagliando?

È stato utile?

Soluzione

Capito. Per chiunque fosse interessato, avevo il mio <filter> attributo nel posto sbagliato:

Prima:

<bag name="Clips" table="ctv_bb_contentAudVidLinks">
  <key column="fk_contentPackageId"></key>
  <many-to-many class="Clip" column="fk_AudVidId"></many-to-many>
  <filter name="effectiveDate" condition=":asOfDate BETWEEN startDate and endDate" />
</bag>

Dopo:

<bag name="Clips" table="ctv_bb_contentAudVidLinks">
  <key column="fk_contentPackageId"></key>
  <many-to-many class="Clip" column="fk_AudVidId">
    <filter name="effectiveDate" condition=":asOfDate BETWEEN startDate and endDate" />
  </many-to-many>
</bag>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top