Hi y'all

I've Implemented a custom fetch strategy
I have a use-case in my app where I need the first two levels of my
object tree.
I have an object called Player which has a list called CheckIns
that holds a many-to-one connection to Player as an object reference

when I execute the Query I get back a seemingly endless chain of
Player->CheckIns->Player->CheckIns and so on..

What I need is Player->CheckIns

the relevant code :

public ICriteria AddFetchJoinTo(ICriteria criteria)
{
   criteria.SetFetchMode("PlayerCheckIns", FetchMode.Join)
                .SetFetchMode("PlayerCheckIns.Player",
FetchMode.Lazy);

   //  I've also tried using Eager on the first SetFetchMode

   return criteria;
}

public IList<T> RetrieveEquals<T>(string propertyName, object
propertyValue, IFetchingStrategy fetchingStrategy)
{
  using (ISession session = m_SessionFactory.OpenSession())
  {
        ICriteria criteria = session.CreateCriteria(typeof(T));
        if (fetchingStrategy != null)
        {
 
fetchingStrategy.AddFetchJoinTo(criteria);
        }
            criteria.Add(Expression.Eq(propertyName, propertyValue));
            // Get the matching objects
            IList<T> matchingObjects =
criteria.List<T>();

            // Set return value
            return matchingObjects;
        }
}

Player.hbm.xml

<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="XXXX"
                   assembly="DAL">

  <!-- Mappings for class 'Customer' -->
  <class name="Player" table="tblPlayers"
         dynamic-update="true" dynamic-insert="true" select-before-
update="true">

    <!-- Identity mapping -->
    <id name="ID">
      <column name="ID" />
      <generator class="native" />
    </id>

    <!-- Bunch of properties I'll spare ya..-->

    <bag name="PlayerCheckIns" cascade="all-delete-orphan"
lazy="true" >
      <key column="PlayerID" />
      <one-to-many class="CheckIn" />
    </bag>

  </class>
</hibernate-mapping>



CheckIn.hbm.xml

<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="XXXXX"
                   assembly="DAL">

  <class name="CheckIn" table="tblCheckIn">

    <!-- Identity mapping -->
    <id name="ID">
      <column name="ID" />
      <generator class="native" />
    </id>

    <!-- Properties-->

    <many-to-one name="Player"  class="Player" column="playerId" />
  </class>
</hibernate-mapping>

thanks alot!
Igal

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to