|
Re: [Teneo] howto refresh objects [message #87764 is a reply to message #87673] |
Fri, 29 June 2007 04:37 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
I think the main reason for this happening are the cascade settings on associations. Teneo sets full
cascade on almost all relations as a default (see the generated hbm and then look for the cascade
attribute). The advantage of this approach is that saving an object will ensure that its related
objects are also always persisted. The disadvantage is that in update (and refresh) scenarios all
related objects will also be read/persisted.
I have changed this behavior (in my development code) as I found this last behavior to be too much
of a disadvantage (the changed behavior is controlled by an option to retain backward
compatibility). In general the better (new) approach is:
- For containment relations always cascade (cascade="all" or cascade="all, delete-orphans") (this is
the current behavior)
- For all other relations do not cascade at all
Especially non-containment many-to-one do most of the time not require a cascade.
As I am still working on this new release of Teneo as a workaround the thing you can do now is
remove the cascade attribute manually in the hbm file or set cascade annotations on all associations
in ecore (or a separate xml). When you remove the cascade attribute from the hbm mapping the rule
is that if cascade="all" or cascade="all, delete-orphan" then it is a containment relation (for
which cascade is logical) and if cascade="refresh, persist, save-update etc. then it is a
non-containment relation which would not require cascade.
There is also a special association which is not visible in the hbm file (Teneo adds it dynamically
to the hibernate mapping): the econtainer handling. A contained object has a pointer to its
container (see the econtainer fields in the db table). When an object is loaded also its container
is loaded automatically. Normally this should not result in a full db load as only the containment
path is loaded.
gr. Martin
Mark wrote:
> I am working on implementing client notifications to support updates
> other clients when a specific client modifies a hibernate object.
>
> I have extended the EMFInterceptor so that I can see when hibernate is
> marking objects dirty, etc. I then grab the EntityName and ID from the
> arguments to onFlushDirty() and broadcast this information to all
> connected/interested clients...
>
> This all works.
>
> However, in the receiving clients I am having trouble refresing the
> objects. I can retreieve the object with session.get(EntityName, ID),
> but a call to session.refresh(object) seems to load the entire hibernate
> persistent database.
>
> I would appreciate any help in this.
>
> Mark.
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
|
|
Re: [Teneo] howto refresh objects [message #608615 is a reply to message #87673] |
Fri, 29 June 2007 04:37 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
I think the main reason for this happening are the cascade settings on associations. Teneo sets full
cascade on almost all relations as a default (see the generated hbm and then look for the cascade
attribute). The advantage of this approach is that saving an object will ensure that its related
objects are also always persisted. The disadvantage is that in update (and refresh) scenarios all
related objects will also be read/persisted.
I have changed this behavior (in my development code) as I found this last behavior to be too much
of a disadvantage (the changed behavior is controlled by an option to retain backward
compatibility). In general the better (new) approach is:
- For containment relations always cascade (cascade="all" or cascade="all, delete-orphans") (this is
the current behavior)
- For all other relations do not cascade at all
Especially non-containment many-to-one do most of the time not require a cascade.
As I am still working on this new release of Teneo as a workaround the thing you can do now is
remove the cascade attribute manually in the hbm file or set cascade annotations on all associations
in ecore (or a separate xml). When you remove the cascade attribute from the hbm mapping the rule
is that if cascade="all" or cascade="all, delete-orphan" then it is a containment relation (for
which cascade is logical) and if cascade="refresh, persist, save-update etc. then it is a
non-containment relation which would not require cascade.
There is also a special association which is not visible in the hbm file (Teneo adds it dynamically
to the hibernate mapping): the econtainer handling. A contained object has a pointer to its
container (see the econtainer fields in the db table). When an object is loaded also its container
is loaded automatically. Normally this should not result in a full db load as only the containment
path is loaded.
gr. Martin
Mark wrote:
> I am working on implementing client notifications to support updates
> other clients when a specific client modifies a hibernate object.
>
> I have extended the EMFInterceptor so that I can see when hibernate is
> marking objects dirty, etc. I then grab the EntityName and ID from the
> arguments to onFlushDirty() and broadcast this information to all
> connected/interested clients...
>
> This all works.
>
> However, in the receiving clients I am having trouble refresing the
> objects. I can retreieve the object with session.get(EntityName, ID),
> but a call to session.refresh(object) seems to load the entire hibernate
> persistent database.
>
> I would appreciate any help in this.
>
> Mark.
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03267 seconds