Hi

I've got a problem with the audit of a table in a sql server 2008
database with C# .net 3.5.

The problem is the following :
I've got a 'Programme' table with an auto increment ID n_programme and
a 'Lot' table that contains the ID of the Programme it is linked to.
A Programme is associated to several Lots so my mapping file looks
like this :

  <class name="Programme" table="Programme">
    <id name="Id" unsaved-value="null" column="n_programme"
type="Int32">
      <generator class="identity"/>
    </id>
    ...
    <bag name="Lot" cascade="all" lazy="true" batch-size="10">
      <key column="n_programme"/>
      <one-to-many class="Lot"/>
    </bag>
  </class>

Everything works fine, except that when I want to audit the Lot
entries after an insert (in a HistoLot table, which contains all the
fields of Lot, plus a modification date and the Programme ID
n_programme), the n_programme field is not filled correctly (NULL
value).
I assume that with the cascade option, the Lot entries are created
before the n_programme is generated, and are then updated with the
value once it is generated. But when I audit the Lot entry on a
PostInsert event, it seems the n_programme is not generated yet, and
that's why the value is NULL.
I also forgot to mention that I perform the audit using a stored
procedure.
Here is my PostInsertEventListener :

    public class LotPostInsertListener : IPostInsertEventListener
    {
        private ILotAuditDao _lotAuditDao;
        public ILotAuditDao LotAuditDao
        {
            set { _lotAuditDao = value; }
        }

        public void OnPostInsert(PostInsertEvent insertEvent)
        {
            if (insertEvent.Entity != null)
            {
                var entity = insertEvent.Entity;
                var lot = entity as Lot;
                if (lot != null)
                {
                    _lotAuditDao.Save(lot, insertEvent.Session);
                }
            }
        }
    }

In the save method, I call the stored procedure as follow :
 currentSession.GetNamedQuery("HistoriserLot")
                    .SetParameter("n_lot", lot.Id.Value)
                    .SetParameter("id_user", Login)
                    .SetParameter("date_histo", DateTimeOffset.Now)
                    .ExecuteUpdate();

I also tried some other EventListeners but can't find if a particular
event is called when the value of n_program is set in the Lot table.

Hope someone can help me with this.

Kévin

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