These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Interceptor FindDirty/OnFlushDirty not working?
PostPosted: Tue Jun 10, 2008 9:33 am 
Beginner
Beginner

Joined: Mon Mar 26, 2007 5:47 am
Posts: 22
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.