I have a problem with a bi-directional mapping where the many-to-one
association refuses to load (it remains as null) despite using
FetchMode.Join. Here is the criteria:

                public List<MessageReceipt> Retrieve(string address, 
MessageStatus
status, int quantity)
                {
                        List<MessageReceipt> list;
                        using (var tx = Session.BeginTransaction())
                        {
                                var criteria = Session.CreateCriteria(typeof 
(MessageReceipt));
                                criteria.SetFetchMode("Message", 
FetchMode.Join);
                                criteria.Add(Restrictions.Eq("Address", 
address));
                                criteria.Add(Restrictions.Eq("Status", status));
                                criteria.AddOrder(new Order("Message", false));
                                criteria.SetFirstResult(0);
                                criteria.SetMaxResults(quantity);
                                list = criteria.List<MessageReceipt>().ToList();
                                tx.Commit();
                        }
                                return list;
                }

The mapping is thus:

        <class name="MessageReceipt" lazy="false" table="MessageReceipts">

                <id name="Id">
                        <generator class="guid.comb"></generator>
                </id>

                <discriminator column="Discriminator"/>
                <property name="Address" />
                <property name="Status" />
                <property name="MarkedAsDeleted" />

                <many-to-one name="Message" column="MessageId" 
class="RootMessage"
not-found="ignore"/>

        </class>

The actual sql produced taken from NHProfiler is this:

SELECT   TOP 5 Id0_1_,
               Address0_1_,
               Status0_1_,
               MarkedAs5_0_1_,
               MessageId0_1_,
               Id3_0_,
               Sender3_0_,
               Sent3_0_,
               Body3_0_,
               Subject3_0_,
               IsDraft3_0_
FROM     (SELECT ROW_NUMBER()
                   OVER(ORDER BY __hibernate_sort_expr_0__ DESC) as
row,
                 query.Id0_1_,
                 query.Address0_1_,
                 query.Status0_1_,
                 query.MarkedAs5_0_1_,
                 query.MessageId0_1_,
                 query.Id3_0_,
                 query.Sender3_0_,
                 query.Sent3_0_,
                 query.Body3_0_,
                 query.Subject3_0_,
                 query.IsDraft3_0_,
                 query.__hibernate_sort_expr_0__
          FROM   (SELECT this_.Id              as Id0_1_,
                         this_.Address         as Address0_1_,
                         this_.Status          as Status0_1_,
                         this_.MarkedAsDeleted as MarkedAs5_0_1_,
                         this_.MessageId       as MessageId0_1_,
                         rootmessag2_.Id       as Id3_0_,
                         rootmessag2_.Sender   as Sender3_0_,
                         rootmessag2_.Sent     as Sent3_0_,
                         rootmessag2_.Body     as Body3_0_,
                         rootmessag2_.Subject  as Subject3_0_,
                         rootmessag2_.IsDraft  as IsDraft3_0_,
                         this_.MessageId       as
__hibernate_sort_expr_0__
                  FROM   MessageReceipts this_
                         left outer join Messages rootmessag2_
                           on this_.MessageId = rootmessag2_.Id
                  WHERE  this_.Address = '[email protected]' /* @p0 */
                         and this_.Status = 1 /* @p1 */) query) page
WHERE    page.row > 0
ORDER BY __hibernate_sort_expr_0__ DESC



It would seem that the sql is getting the correct information to
hydrate the association to the message, yet when accessing the
property it just returns NULL - Can any one help?


--~--~---------~--~----~------------~-------~--~----~
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