Well that's quite simple to do :
- You create your poco implementing INotifyPropertyChanged
- You handle persistence via use of Stateless session
Another good example would be to look at ActiveRecord implementation.
For the "record", when hibernate (not nhibernate) was created in 2001
and focusing on EJB 2 / EJB (EJB2 was painfull to develop) and focused
on JEE, meaning a web based approach : that is stateless. Whatever the
artefact or the framework the web is stateless by essence.
I don't know if some of you are familiar with the EJBObject and the
EntityBean principle, but the architecture was made of different layer
(EJB, Home, Local, Bean), that could be compared to the .Net Proxy,
Contracts and Services and Activator and DTO; the bean being responsible
for holding its context (What fun memories !!!).
The question was already existing (could it be IIOP, RMI, or a high
level principle like WCF) :
- If you are exposing a method like a business treatment, you shouldn't
be limited in your design by a specific implementation (even if EJB was
implementing interface, it was a lot of redudant code)
- If you are using a stateless behavior, you are "blind" from the Db
- Distribution is also taking in account
* Objects Graph size (Size does matter)
* Latency
Given this, hibernate is built on a 3 tiers and distributed stateless
approach, working on the object paradigm rather than relationnal paradigm.
History has proven that "persistence ignorance" is a sweet dream.
Yet the most common mistake today is not about tracking change, it is to
understand to an application is not by definition made of one layer.
Most of developpers don't use composition, flyweight, factories. They
build a concrete object, as simple as possible and they want to send it
over the wire, manipulate it, send it back and save it. Well fine. But
that's crud. And that's not suitable for complex application or for
every scenario. The business is not always the data.
I'll take a simple example :
I have a Stock like
public class Stock
{
public string Ric{get;set;}
public string Description {get;set;}
public Currency RefCurrency {get;set;}
public IList Prices {get;set;}
}
public class Currency
{
public string Iso3A {get;set}
public string Description {get;set;}
public IList FxRate {get;set}
}
My Need :
- Having Combo box fill with Stocks
- Having Combo box filled with Currencies
- Pricing the equity against a given currency :
Price (date pricedate,currency ccy)
The reality is that if I need to build a reliable application, I just
can't rely on a naive domain model. I need to use component,
But then in a stateless situation, I need to handle that I can't hit the
Db or whatever the data came from (TCP network, file, xl, dde server....).
And that is exactly why NHibernate is good by design : I can have
multiple object with a coherent and independent data management.
I mean that I don't need to carry all the FxRates, Or I don't need to
have a mutable instance.
Of course I'm multiplying my objects, but that's exactly why service
layer and contracts exists : to define responsability.
And that's the purpose of an ORM (aside from the best practices
regarding performances and SQL and local framework)
My point is : this is not at ORM level. It is at the view engine level.
You can choose, to clone, use DTO, equality. But a "Technical" undoable
object is a bomb. Not because you undo properties, but because you may
undo processes and propagate events.
You have clean and reliable objects. Up to the developper to carefully
handle them; NHibernate is a tool. You may use interceptor, events,
attach/detach. These are only technical options. If you don't know why
you would need to track change inside an entity (have fun if you send
you entity over the wire and change and object reference with a
relationship) it is quite useless to bring up technical solution.
Fred.
Le 04/09/2010 20:33, Diego Mijelshon a écrit :
I believe it's absolutely doable... but it wouldn't be NHibernate
anymore :-)
Diego
On Sat, Sep 4, 2010 at 14:17, nadav s <[email protected]
<mailto:[email protected]>> wrote:
yeah, but it wouldn't it be a better way to track the entities? as
they will actually track themselves through different sessions,
althoguh there might be implications because the entities returned
from nhibernate will always be proxies
i'm just curious weather this idea is doable and weather it can
actually help
On Fri, Sep 3, 2010 at 11:51 PM, Diego Mijelshon
<[email protected] <mailto:[email protected]>> wrote:
That basically requires changing the way NH tracks the entities...
Diego
On Fri, Sep 3, 2010 at 09:47, nadav s <[email protected]
<mailto:[email protected]>> wrote:
would it be a nice feature if the entities will keep their
previous state? using proxies?
the problem is that this way all the entities will be
proxies, but they will keep their state through different
sessions
On Fri, Sep 3, 2010 at 1:10 PM, Ricardo Peres
<[email protected] <mailto:[email protected]>> wrote:
Amir,
The short answer is: you can't. If the entity is not
attached to a
session, there's no way to know its original values,
because
NHibernate entities are not self-tracking (Entity
Framework 4, among
others, does support this).
What you could do is load an entity by id in another
session and
compare the values (assuming not too many of them).
RP
On Sep 3, 3:45 am, Amir Rasekh <[email protected]
<mailto:[email protected]>> wrote:
> I use short life session in my windows application,
and the session is
> not available now.
> Can I use merge for detached object in new session?
>
> On Sep 1, 1:11 pm, Valeriu Caraulean
<[email protected] <mailto:[email protected]>> wrote:
>
>
>
> > You can try attach object back to session and then
do the check.
> > Look at ISession.Merge(...) method.
>
> > On Wed, Sep 1, 2010 at 10:21 AM, Amir Rasekh
<[email protected] <mailto:[email protected]>>
wrote:
> > > Hi there,
>
> > > There is some methods for checking dirty
object/property at
> >
>http://nhforge.org/wikis/howtonh/finding-dirty-properties-in-nhiberna...
> > > .
>
> > > Bu it works is a session lifecycle.
>
> > > If I want to check a detached object from
session, How I can do it?
>
> > > Is it possible?
>
> > > thanks.
> > > --
> > > You received this message because you are
subscribed to the Google Groups
> > > "nhusers" group.
> > > To post to this group, send email to
[email protected]
<mailto:[email protected]>.
> > > To unsubscribe from this group, send email to
> > > [email protected]
<mailto:nhusers%[email protected]><nhusers%[email protected]
<mailto:nhusers%[email protected]> >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/nhusers?hl=en.
--
You received this message because you are subscribed
to the Google Groups "nhusers" group.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:nhusers%[email protected]>.
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.
--
You received this message because you are subscribed to
the Google Groups "nhusers" group.
To post to this group, send email to
[email protected] <mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:nhusers%[email protected]>.
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.
--
You received this message because you are subscribed to the
Google Groups "nhusers" group.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:nhusers%[email protected]>.
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.
--
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:nhusers%[email protected]>.
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.
--
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.
--
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.