In what moment the flush/commit is taking part ? At the very ending of the
request or in your business/service code ?

On Fri, Jun 19, 2009 at 5:04 PM, Gary Brunton <[email protected]> wrote:

>
> I'm not so sure I was very clear in explaining my problem.
> Essentially the NHibernate session gets flushed/committed from an
> HttpModule on every page request so if the session contains an invalid
> entity, an InvalidStateExpection will be thrown.
>
> What I've decided to do is just clear the NHibernate session if a
> validation error is found from an entity that was retrieved from the
> repository (not newed up) and had a field set to an invalid value.
> This way when the session gets flushed/committed it won't contain the
> invalid entity.
>
>
> Now I'm not sure that this expatiation is any better but I wanted to
> update what I've decided just in case this does make sense to someone.
>
> Thanks!
> Gary Brunton
>
>
>
>
> On Jun 17, 4:18 pm, Fabio Maulo <[email protected]> wrote:
> > If you need to validate in some other point you can implements others
> > listeners but, in general, the validation happen in some other
> high-level.
> > 2009/6/17 Gary Brunton <[email protected]>
> >
> >
> >
> >
> >
> > > I just started looking into NHibernate.Validator and love the
> > > integration it has with NHibernate.  I do have a question though.
> >
> > > I see many examples of how to perform validation using NHV on a newly
> > > created entity like so:
> >
> > > Customer customer = new Customer();
> > > ...
> > > customer.Phone = "343-343-343"; //INVALID VALUE
> > > customer.Zip = "34334"; //INVALID VALUE
> >
> > > ValidatorEngine validator = new ValidatorEngine();
> >
> > > if (validator.IsValid(customer))
> > > {
> > >  repo.Save(customer);
> > > }
> >
> > > But I can't find an example of performing validation on an entity
> > > retrieved from a repository and then updated.  ex:
> >
> > > Customer customer = repo.Get(1);
> > > ...
> > > customer.Phone = "343-343-343"; //INVALID VALUE
> >
> > > foreach (InvalidValue error in validatorEngine.Validate(customer))
> > > {
> > >  // display the errors...
> > > }
> >
> > > from here I can retrieve the validation errors no problem but the
> > > customer entity is now dirty and my unit of work will try to flush/
> > > commit the changes which causes an InvalidStateException.  I don't
> > > want to handle this exception here as it is assumed I've already
> > > realized the entity is invalid and handled the validation errors as
> > > desired.
> >
> > > Now from here I see a couple of options that I don't like:
> > > 1. I could swallow all InvalidStateExceptions
> > > 2. I could set some global error state when a validation error has
> > > been found by the validation engine and then always check this global
> > > error state before flushing/committing within my UOW.
> >
> > > Am I missing something here?
> >
> > > Any insight would be greatly appreciated. Thanks!
> >
> > > Gary Brunton
> >
> > --
> > Fabio Maulo
> >
>
>


-- 
Dario Quintana
http://darioquintana.com.ar

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