Due to the nature of our application, we treat every value type as
immutable. Hence, when an immutable type is loaded from the database, we
absolutely want this type to be valid, if not - we throw an unexpected
exception straight away!

The loading of the entity calls the private default constructor thereby
generating an instance of the entity with data retrieved from the database.
However we then use a PostLoadEventListener to validate the entity by
calling the constructor where entity validation takes place. It is a
workaround but we guarentee that all value types loaded from the database
are valid.

The only requirement that we failed to achieve was integrating NHibernate
into the codebase achieving 100% "persistence ignorance" in our domain - due
to requiring a private default constructor in entities.
However, NHibernate brings many benefits, so we could not justify leaving
NHibernate out due to the default constructor requirement!

If I am not mistaken, this issue is a general ORM issue anyway...
2009/1/2 Humberto Marchezi <[email protected]>

> Hi,
>
> Is it really a good idea to validate instances retrieved from the database
> ?
>
> For me, it sounds like a non-robust software.
> Imagine if someone or some external system performs updates in the database
> that breaks your constraints. Will your software trigger exceptions all the
> time whenever an "invalid" instance is retrieved from the database ?
> How about perform validations when this instance is saved again and give a
> chance to the user to fix the data if he/she finds it necessary ?
>
>
>
> 2008/12/30 Ayende Rahien <[email protected]>
>
>> What is real proxy?
>>
>> 2008/12/31 Greg Young <[email protected]>
>>
>> This leads to the use of "real proxies" as opposed to instance proxies.
>>>
>>> The use of real proxies leads to the "leaky this" problem.
>>>
>>> The "leaky this" problem leads to a great amount of complexity.
>>>
>>> Cheers,
>>>
>>> Greg
>>>
>>> 2008/12/30 Ayende Rahien <[email protected]>:
>>>  > session.Load<Customer>(5); // doesn't hit the db, so we don't HAVE
>>> any way
>>> > to provide those values.
>>> > session.Get<Order>(15);// we need to provide a value for
>>> Order.Customer, but
>>> > we don't want to load that data
>>> >
>>> > 2008/12/30 Krzysztof Koźmic <[email protected]>
>>> >>
>>> >> Do you mean proying dependencies for lazy loading? so that instead of
>>> >> CustomerName instance I get a proxy?
>>> >> Can you elaborate on that? I'm not sure I understand your answer.
>>> >>
>>> >> Krzysztof
>>> >>
>>> >> Ayende Rahien pisze:
>>> >>
>>> >> Proxies
>>> >>
>>> >> On Tue, Dec 30, 2008 at 11:33 PM, Krzysztof Koźmic
>>> >> <[email protected]> wrote:
>>> >>>
>>> >>> Greg Young pisze:
>>> >>>
>>> >>> Fabio this discussion has already happened and I prefer to not
>>> restate
>>> >>> the same positions as before but ... in terms of insuring correctness
>>> >>> assuming that data from the database is correct is a nefarious at
>>> best
>>> >>> course of action.
>>> >>>
>>> >>>
>>> >>> True, especially if you consider schema changes or access to DB
>>> bypassing
>>> >>> the app.
>>> >>> I mean, aside from how NH is currently implemented - how is having
>>> only
>>> >>> non-default .ctor and required value type dependencies a bad idea?
>>> >>>
>>> >>> Krzysztof
>>> >>>
>>> >>> On Tue, Dec 30, 2008 at 11:31 AM, Fabio Maulo <[email protected]>
>>> >>> wrote:
>>> >>>
>>> >>>
>>> >>> 2008/12/30 Greg Young <[email protected]>
>>> >>>
>>> >>>
>>> >>> To not be able to insure validity upon construction is a very large
>>> cost.
>>> >>>
>>> >>>
>>> >>> Really not for me; the default ctor is private and used only for
>>> upload
>>> >>> from
>>> >>> persistence.
>>> >>> --
>>> >>> Fabio Maulo
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >
>>> >
>>> > >
>>> >
>>>
>>>
>>>
>>> --
>>> It is the mark of an educated mind to be able to entertain a thought
>>> without accepting it.
>>>
>>>
>>>
>>
>>
>>
>
>
> --
> Humberto C Marchezi
> ---------------------------------------------------------
> Master in Electrical Engineering - Automation
> Software Consultant and Developer
> at the Town Hall of Vitória
>
>
> >
>

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