Hi,
I want to prevent several objects from updating using the Interceptor. I've found some semi-samples, but it doesn't seem to work.
If I am not wrong, I should return an empty array when I don't want to have the object saved, but it still saves it...
Anybody has any idea? A working sample? You can find my code underneath.
Thanks a lot in advance,
Pieter
Hibernate version: 1.2
The code:
Code:
Option Explicit On
Imports NHibernate
Imports NHibernate.Cfg
Namespace BusinessLayer.Factory
Public Class NHibernateInterceptor
Inherits EmptyInterceptor
Public Overrides Function FindDirty(ByVal entity As Object, ByVal id As Object, ByVal currentState() As Object, ByVal previousState() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) As Integer()
'when we are loading an object and some of it's properties are changed: we don't want to have it saved automaticly to the database!
If CType(entity, BaseClass).IsDoingLoad Then
'in this case we have to return an empty array of integers
'Dim intA(propertyNames.Length - 1) As Integer
Dim intA(-1) As Integer
Return intA
Else
'normal case: 'call the MyBase
Dim intB(propertyNames.Length - 1) As Integer
intB = MyBase.FindDirty(entity, id, currentState, previousState, propertyNames, types)
Return intB
End If
End Function
Public Overrides Function OnFlushDirty(ByVal entity As Object, ByVal id As Object, ByVal currentState() As Object, ByVal previousState() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) As Boolean
Dim bln As Boolean
bln = MyBase.OnFlushDirty(entity, id, currentState, previousState, propertyNames, types)
Return bln
End Function
Public Overrides Function OnLoad(ByVal entity As Object, ByVal id As Object, ByVal state() As Object, ByVal propertyNames() As String, ByVal types() As NHibernate.Type.IType) As Boolean
Dim MyBaseClass As BaseClass = CType(entity, BaseClass)
'method which has to be executed when an object is Loaded from the database
MyBaseClass.BeforeLoad()
'call the MyBase
Return MyBase.OnLoad(entity, id, state, propertyNames, types)
End Function
End Class
End Namespace