Ok, finally I've decided to use Interceptors after reading more about
them.
I've added the following in the my value object class :
public override bool OnFlushDirty(object entity, object id, object[]
currentState, object[] previousState,
string[] propertyNames, IType[]
types)
{
if (entity is Source)
{
for (int i = 0; i < propertyNames.Length; i++)
{
if ("DateModified" == propertyNames[i])
{
currentState[i] = DateTime.Now;
return true;
}
}
}
return false;
}
and my value object class now inherits EmptyInterceptor.
The problem is that when I run the code I get the following
exceptions... Somehow it makes sense as every methods or properties in
my value object should be virtual since they can be 'proxied' by NH.
So what should I do ?
SourceDaoTests.SaveSource :
FailedNHibernate.InvalidProxyTypeException: The following types may
not be used as proxies:
Metrica.OnlineSource: method GetEntityName should be virtual
Metrica.Source: method OnPrepareStatement should be virtual
Metrica.BroadcastSource: method OnPrepareStatement should be virtual
Metrica.OnlineSource: method OnCollectionUpdate should be virtual
Metrica.OnlineCGMSource: method OnCollectionRemove should be virtual
Metrica.OnlineCGMSource: method OnCollectionUpdate should be virtual
Metrica.PrintSource: method OnCollectionRecreate should be virtual
Metrica.PrintSource: method GetEntity should be virtual
Metrica.Source: method OnCollectionRecreate should be virtual
Metrica.OnlineMSMSource: method GetEntityName should be virtual
Metrica.Source: method OnCollectionRemove should be virtual
Metrica.OnlineCGMSource: method GetEntityName should be virtual
Metrica.PrintSource: method GetEntityName should be virtual
Metrica.Source: method OnCollectionUpdate should be virtual
Metrica.OnlineSource: method OnPrepareStatement should be virtual
Metrica.BroadcastSource: method OnCollectionUpdate should be virtual
Metrica.Source: method GetEntityName should be virtual
Metrica.PrintSource: method OnCollectionUpdate should be virtual
Metrica.BroadcastSource: method OnCollectionRemove should be virtual
Metrica.PrintSource: method OnPrepareStatement should be virtual
Metrica.PrintSource: method OnCollectionRemove should be virtual
Metrica.OnlineCGMSource: method OnPrepareStatement should be virtual
Metrica.OnlineMSMSource: method OnCollectionRemove should be virtual
Metrica.OnlineCGMSource: method GetEntity should be virtual
Metrica.OnlineMSMSource: method GetEntity should be virtual
Metrica.BroadcastSource: method GetEntityName should be virtual
Metrica.OnlineSource: method OnCollectionRemove should be virtual
Metrica.OnlineMSMSource: method OnPrepareStatement should be virtual
Metrica.OnlineMSMSource: method OnCollectionUpdate should be virtual
Metrica.BroadcastSource: method OnCollectionRecreate should be virtual
Metrica.OnlineSource: method GetEntity should be virtual
Metrica.OnlineSource: method OnCollectionRecreate should be virtual
Metrica.Source: method GetEntity should be virtual
Metrica.OnlineCGMSource: method OnCollectionRecreate should be virtual
Metrica.OnlineMSMSource: method OnCollectionRecreate should be virtual
Metrica.BroadcastSource: method GetEntity should be virtual
at NHibernate.Cfg.Configuration.Validate()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at Metrica.Data.HibernateHelper.SessionManager.BuildSessionFactory
(Database pDatabase) in SessionManager.cs: line 85
at Metrica.Data.Tests.SourceDaoTests.SetUp() in SourceDaoTests.cs:
line 24
On 23 avr, 18:51, Fabio Maulo <[email protected]> wrote:
> <version>
>
> 2009/4/23 graphicsxp <[email protected]>
>
>
>
> > Hi,
>
> > I have a property DateModified on my entity which map to a date field
> > in my database table. I'd like this field to be updated with the
> > current date whenever an update is perform on the table. Is it
> > possible to do that directly in the mapping file ? If so, what the
> > syntax for that ?
>
> > Thanks
>
> --
> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---