ORMValidationException Strange Behavior with Self Servicing

Posts   
 
    
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 19-Oct-2006 11:56:41   

Hi there!

I've come up against a strange behavior when trying to save a collection of entities.

I'm using self servicing; and I've assigned a validator class to my entity. When saving the collection bound to my data form and the entity validation fails an unhandled exception occurs.



Try

            Dim x As BankEntity = CType(Me.bindSource.Current, BankEntity)
            x.Validator = New DAL.ValidatorClasses.BankValidator

            'Display message when NOT saved
            'This fails!!!
            If Me.colBank.SaveMulti(True) = 0 Then

                If DisplayMessage = True Then
                    MessageBox.Show("Your entry has NOT been saved. Please try again later.", "Saving Failure ...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If

                Return False
            Else
                Return True
            End If

        Catch exJCL As SD.LLBLGen.Pro.ORMSupportClasses.ORMEntityValidationException
            MessageBox.Show(exJCL.Message, "Bashar Lulu")

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Bashar Lulu")

        End Try


When saving only a single entity (again, and the validation fails) then the exception is handled properly.



Try

            Dim x As BankEntity = CType(Me.bindSource.Current, BankEntity)
            x.Validator = New DAL.ValidatorClasses.BankValidator

            'Display message when NOT saved
            'This is OK!!!
            If Me.CurrentEntity.Save(True) = False Then

                If DisplayMessage = True Then
                    MessageBox.Show("Your entry has NOT been saved. Please try again later.", "Saving Failure ...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If

                Return False
            Else
                Return True
            End If

        Catch exJCL As SD.LLBLGen.Pro.ORMSupportClasses.ORMEntityValidationException
            MessageBox.Show(exJCL.Message, "Bashar Lulu")

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Bashar Lulu")

        End Try


What's wrong? I'm using LLBL v2, BTW.

Thanks, Bashar

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 19-Oct-2006 16:15:33   

I'm using self servicing; and I've assigned a validator class to my entity. When saving the collection bound to my data form and the entity validation fails an unhandled exception occurs.

Please post the exception text and the stack trace.

I see you have a Validator Class (BankValidator), but I don't see you assign it to the entities inside the Collection to be saved.

Also please post the code of the BankValidator class.

And please post the Runtime library version as shown in the following guide: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7725

Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 20-Oct-2006 06:14:21   

I'm sorry my mistake. confused

Here is the info you requested.

Runtime library version: 2.0.0.61005



    Public Class BankValidator
        Inherits ValidatorBase

        ''' <summary>
        ''' Method to validate the containing entity right before the save sequence for the entity will start. LLBLGen Pro will call this method right after the
        ''' containing entity is selected from the save queue to be saved.
        ''' </summary>
        ''' <param name="involvedEntity">The involved entity.</param>
        Public Overrides Sub ValidateEntityBeforeSave(ByVal involvedEntity As IEntityCore)

            Dim toValidate As BankEntity = CType(involvedEntity, BankEntity)
            If String.IsNullOrEmpty(toValidate.StrBank) = True Then
                Throw New ORMEntityValidationException("Invalid Bank Name", toValidate)
            End If
            'If toValidate.VisitingAddress Is Nothing Then
            '   Throw New ORMEntityValidationException("VisitingAddress can't be null", toValidate)
            'End If

            MyBase.ValidateEntityBeforeSave(involvedEntity)

        End Sub

    End Class


Also, I am assigning the validator class to the entities inside the collection to be saved; CType(Me.bindSource.Current, BankEntity) is the same as Me.CurrentEntity

Thank you for your help.

Bashar

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 20-Oct-2006 09:41:54   

The exception text and the stack trace, please.

Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 20-Oct-2006 11:44:31   

Ok.


SD.LLBLGen.Pro.ORMSupportClasses.ORMEntityValidationException was unhandled by user code
  Message="Invalid bank name."
  Source="DAL"
  StackTrace:
       at DAL.ValidatorClasses.BankValidator.ValidateEntityBeforeSave(IEntityCore involvedEntity) in D:\Bashar Lulu\My Documents\Visual Studio 2005\ShareRegister\DAL\ValidatorClasses\BankValidator.vb:line 18
       at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.OnValidateEntityBeforeSave()
       at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.CallValidateEntityBeforeSave()
       at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, ITransaction transactionToUse)
       at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.PerformSaveMulti(Boolean recurse)
       at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.SaveMulti(Boolean recurse)


Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-Oct-2006 17:28:09   

So the validation works, it throws the exception correctly, but the catch clause doesn't catch it apparently?

What I find odd, is that your try clause has a catch clause with 'Exception' as well, so no matter what, no exception should bubble upwards... confused

Frans Bouma | Lead developer LLBLGen Pro
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 21-Oct-2006 09:18:52   

smile This was only for me to test.

I did that because the catch clause was not 'catching' validation exceptions so I thought maybe I was doing something wrong.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Oct-2006 10:58:29   

But... there's still a problem with the code? As I'm at a loss now what's wrong. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 21-Oct-2006 11:50:17   

The problem is, although I'm handling the error, my application breaks when using;


Me.colBank.SaveMulti(True)


However, when using;


Me.CurrentEntity.Save(True)


my application does NOT break.

Why? confused

Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 26-Oct-2006 09:28:55   

Hello...

Is the problem clear, or do you need further info? smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Oct-2006 10:03:08   

Bashar wrote:

Hello...

Is the problem clear, or do you need further info? smile

I'm not grasping WHAT the problem exactly is, so please clarify this for us: is the error either: 1) you throw an exception and that's not caught by the catch clause you specified OR 2) you set a validator but it's not triggered when you save a single entity.

Frans Bouma | Lead developer LLBLGen Pro
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 26-Oct-2006 11:35:38   

The error is;

'I'm throwing an exception and it is not caught by the catch clause I specify'

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Oct-2006 11:59:11   

Then I don't know what's causing it other than that some kind of type mixup is occuring: the exception is thrown in the validator class which refers to instance A of the ormsupportclasses dll, and you catch the exception in code which refers to instance B of the ormsupportclasses.

I have NO IDEA why this happens but it's the only explanation why, as you catch ALL exceptions and still it passes through...

Frans Bouma | Lead developer LLBLGen Pro
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 26-Oct-2006 12:47:05   

Thanks Frans smile

I'll figure out a way to fix this, I hope! confused

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Oct-2006 12:58:30   

Bashar wrote:

Thanks Frans smile

I'll figure out a way to fix this, I hope! confused

As this is a webapp, try to do a deploy of the website and try to run that. I know this sounds silly, but it's odd what happens in asp.net 2.0 apps. For example, take 2 pages, both use llblgen pro code. I build the webapp, run page 1. Works fine. Then I alter page 2. Build, run page 2, doesn't work. Go back to page 1. does work, however it shouldn't work either because I made an error in the ormsupport classes so it should be affected AS WELL.

Apparently somewhere dlls are kept in memory or something, I've no idea. All I know is that it's frustrating and time consuming and I really wonder why the ASP.NET team spends so much time on Atlas instead of fixing basic sillyness in vs.net 2005.

Frans Bouma | Lead developer LLBLGen Pro