You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by tobi <to...@code-sourcery.de> on 2012/11/22 11:09:53 UTC

How important is detaching models really ?

Hi guys,

 From my understanding & experiments with Wicket's built-in session 
inspector , detaching models seems to just affect the size of the page 
store (and of course cut-down the amount of I/O required for serializing 
the object graph). The session size shown on my pages is a constantly 
low value (<1k , we're storing nothing except the currently logged-in user).

So it *seems* not detaching models has no effect on the (long-term) 
memory footprint of a Wicket application.

According to 
https://cwiki.apache.org/WICKET/working-with-wicket-models.html , not 
detaching models should affect the session size but at least looking at 
the inspector I can't see this. Is the wiki article still correct / the 
inspector not telling the truth ?

Thanks,
Tobias

P.S. I'm using Wicket 1.5.8 btw

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: How important is detaching models really ?

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
A similar scenario applies when using Wicket with JDO.

You can use simple LDM when dealing with read only model objects.
However, when you deal with model objects that are the subject of
modification in a form you need to use JDO's detach/reattach mechanism
which allows the form elements to keep references to serializable,
detachable (and reattachable) copies of the object(s) being modified.
This means all changes the user makes to the model objects are preserved
across multiple HTTP requests (AJAX or opening new panels in a wizard
style form) but not written to the DB. 

It's important to note (and this applies to any ORM that supports
detach/attach) that the detach/attach cycle for objects being modified
are not the same times as a typical LDM detach/attach (i.e. typically
with the http request cycle). It's also important to note that Wicket
'detach' is not the same as ORM 'detach' although you can perform an ORM
detach inside a wicket detach method.

When setting up an object for modification you load the objects required
by the form and then perform a single detach so the object has a
persistent ID but it no longer attached to the PersistenceManager(JDO)
or Session(Hibernate/JPA). As many http requests can come and go as you
like but until the user clicks OK or Submit on the form there should be
no more ORM detaches or attaches peformed. 

Clicking Ok or Submit in the form performs a reattach and then you
commit your transaction. It is at this point that any
OptimisticVerificationExceptions will be raised if an object the user
was editing was changed by another user or another process so you need
to wrap this 'commit' inside an appropriate try/catch and warn the user
(eg., with a modal form) that an object they were modifying had been
modified by another user.

JDO manages all the detach/attach for you. I just wrap the detach/attach
in a custom IModel.

"Back in my day we didn't need Wicket, Tapestry, JSF or WebObjects, or
even Servlets, or for that matter Java! We just coded in plain assembly
language. And before that we had to just type in 1's and 0's. Sometimes
we didn't even have 1's. I once had to code for an entire month,
barefoot, in the dead of winter, using just 0's... but you didn't hear
me complaining."

> -----Original Message-----
> From: Martijn Dashorst [mailto:martijn.dashorst@gmail.com]
> Sent: Wednesday, 28 November 2012 11:19 PM
> To: users@wicket.apache.org
> Subject: Re: How important is detaching models really ?
> 
> On Wed, Nov 28, 2012 at 8:28 AM, Marios Skounakis <ms...@gmail.com>
> wrote:
> > Hi Colin,
> >
> > I find I am in agreement with your points about lazy loaded parts of
the
> > data model and how this can be simplified if you use LDMs.
> >
> > However, if you use LDMs for edit pages, you need to deal with
> concurrency
> > issues yourself. You cannot rely on Hibernate's optimistic
concurrency
> > mechanism (version). Because every time your LDM fetches a fresh
> instance
> > of the entity, you can never have a StaleObjectException. Dealing
with
> > concurrency yourself may be as easy as keeping the version property
in
> addition
> > to the Id property in the LDM, and checking against it when
re-attaching
> > the model, but this does add some complexity to the application
code.
> >
> > Any thoughts on this?
> 
> From the good old days:
> http://martijndashorst.com/blog/2006/02/13/wicket-goodie-hibernate-
> versioned-form/
> 
> Martijn
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How important is detaching models really ?

Posted by Martijn Dashorst <ma...@gmail.com>.
On Wed, Nov 28, 2012 at 8:28 AM, Marios Skounakis <ms...@gmail.com> wrote:
> Hi Colin,
>
> I find I am in agreement with your points about lazy loaded parts of the
> data model and how this can be simplified if you use LDMs.
>
> However, if you use LDMs for edit pages, you need to deal with concurrency
> issues yourself. You cannot rely on Hibernate's optimistic concurrency
> mechanism (version). Because every time your LDM fetches a fresh instance
> of the entity, you can never have a StaleObjectException. Dealing with
> concurrency yourself may be as easy as keeping the version property in addition
> to the Id property in the LDM, and checking against it when re-attaching
> the model, but this does add some complexity to the application code.
>
> Any thoughts on this?

>From the good old days:
http://martijndashorst.com/blog/2006/02/13/wicket-goodie-hibernate-versioned-form/

Martijn

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How important is detaching models really ?

Posted by Marios Skounakis <ms...@gmail.com>.
Hi Colin,

I find I am in agreement with your points about lazy loaded parts of the
data model and how this can be simplified if you use LDMs.

However, if you use LDMs for edit pages, you need to deal with concurrency
issues yourself. You cannot rely on Hibernate's optimistic concurrency
mechanism (version). Because every time your LDM fetches a fresh instance
of the entity, you can never have a StaleObjectException. Dealing with
concurrency yourself may be as easy as keeping the version property in addition
to the Id property in the LDM, and checking against it when re-attaching
the model, but this does add some complexity to the application code.

Any thoughts on this?

Cheers
Marios



On Wed, Nov 28, 2012 at 2:10 AM, Colin Rogers <
Colin.Rogers@objectconsulting.com.au> wrote:

> Tobias,
>
> I also find it's really important when using Hibernate. Hibernate is a
> total dog unless all your fetches are Lazy (so you only load what you
> need). With any UI, you load your entity and display a certain amount, but
> based on user action, you might need lazy loaded dependencies - with a
> loadable detachable model, the main entity is always 'fresh' in the session
> and lazily loaded dependencies are always available. It means everything in
> your data can be specified to be lazy loaded. Your data model is clean,
> your UI is clean.
>
> In other UIs frameworks, or when I've used Wicket without LDMs, I spend
> half my time dealing with Lazy Load Exceptions, or having to pre-load
> certain lazy loaded entities for certain screens, that may or may not ever
> be used. You end up changing your data model to fit your UI (ugh!) or
> having tons of duplicated, effectively redundant, UI specific service
> methods (ugh!).
>
> Cheers,
> Col.
>
> -----Original Message-----
> From: Chris Colman [mailto:chrisc@stepaheadsoftware.com]
> Sent: Friday, 23 November 2012 12:53 AM
> To: users@wicket.apache.org
> Subject: RE: How important is detaching models really ?
>
> I guess in more complex apps the UI elements end up with lots of
> references to model objects so detaching does save a lot of memory and it
> also makes transferring session data from one web server to another (if
> required) in a multi server environment, much more efficient. I have
> experienced the result of accidentally serializing an object graph with
> megabytes of data that didn't use detach - ouch!
>
> The other benefit of detaching is your model will expose updates to the UI
> (if a redisplay occurred) that were made in other ORM sessions (depending
> on your ORM). Keeping a non detached copy of the model object will
> typically be like caching it in it's current state for most ORMs - i.e. it
> can get stale
>
> >-----Original Message-----
> >From: tobi [mailto:tobias.gierke@code-sourcery.de]
> >Sent: Thursday, 22 November 2012 9:10 PM
> >To: users@wicket.apache.org
> >Subject: How important is detaching models really ?
> >
> >Hi guys,
> >
> > From my understanding & experiments with Wicket's built-in session
> >inspector , detaching models seems to just affect the size of the page
> >store (and of course cut-down the amount of I/O required for
> serializing
> >the object graph). The session size shown on my pages is a constantly
> >low value (<1k , we're storing nothing except the currently logged-in
> >user).
> >
> >So it *seems* not detaching models has no effect on the (long-term)
> >memory footprint of a Wicket application.
> >
> >According to
> >https://cwiki.apache.org/WICKET/working-with-wicket-models.html , not
> >detaching models should affect the session size but at least looking at
> >the inspector I can't see this. Is the wiki article still correct / the
> >inspector not telling the truth ?
> >
> >Thanks,
> >Tobias
> >
> >P.S. I'm using Wicket 1.5.8 btw
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >For additional commands, e-mail: users-help@wicket.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
> EMAIL DISCLAIMER This email message and its attachments are confidential
> and may also contain copyright or privileged material. If you are not the
> intended recipient, you may not forward the email or disclose or use the
> information contained in it. If you have received this email message in
> error, please advise the sender immediately by replying to this email and
> delete the message and any associated attachments. Any views, opinions,
> conclusions, advice or statements expressed in this email message are those
> of the individual sender and should not be relied upon as the considered
> view, opinion, conclusions, advice or statement of this company except
> where the sender expressly, and with authority, states them to be the
> considered view, opinion, conclusions, advice or statement of this company.
> Every care is taken but we recommend that you scan any attachments for
> viruses.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

RE: How important is detaching models really ?

Posted by Colin Rogers <Co...@objectconsulting.com.au>.
Tobias,

I also find it's really important when using Hibernate. Hibernate is a total dog unless all your fetches are Lazy (so you only load what you need). With any UI, you load your entity and display a certain amount, but based on user action, you might need lazy loaded dependencies - with a loadable detachable model, the main entity is always 'fresh' in the session and lazily loaded dependencies are always available. It means everything in your data can be specified to be lazy loaded. Your data model is clean, your UI is clean.

In other UIs frameworks, or when I've used Wicket without LDMs, I spend half my time dealing with Lazy Load Exceptions, or having to pre-load certain lazy loaded entities for certain screens, that may or may not ever be used. You end up changing your data model to fit your UI (ugh!) or having tons of duplicated, effectively redundant, UI specific service methods (ugh!).

Cheers,
Col.

-----Original Message-----
From: Chris Colman [mailto:chrisc@stepaheadsoftware.com]
Sent: Friday, 23 November 2012 12:53 AM
To: users@wicket.apache.org
Subject: RE: How important is detaching models really ?

I guess in more complex apps the UI elements end up with lots of references to model objects so detaching does save a lot of memory and it also makes transferring session data from one web server to another (if required) in a multi server environment, much more efficient. I have experienced the result of accidentally serializing an object graph with megabytes of data that didn't use detach - ouch!

The other benefit of detaching is your model will expose updates to the UI (if a redisplay occurred) that were made in other ORM sessions (depending on your ORM). Keeping a non detached copy of the model object will typically be like caching it in it's current state for most ORMs - i.e. it can get stale

>-----Original Message-----
>From: tobi [mailto:tobias.gierke@code-sourcery.de]
>Sent: Thursday, 22 November 2012 9:10 PM
>To: users@wicket.apache.org
>Subject: How important is detaching models really ?
>
>Hi guys,
>
> From my understanding & experiments with Wicket's built-in session
>inspector , detaching models seems to just affect the size of the page
>store (and of course cut-down the amount of I/O required for
serializing
>the object graph). The session size shown on my pages is a constantly
>low value (<1k , we're storing nothing except the currently logged-in
>user).
>
>So it *seems* not detaching models has no effect on the (long-term)
>memory footprint of a Wicket application.
>
>According to
>https://cwiki.apache.org/WICKET/working-with-wicket-models.html , not
>detaching models should affect the session size but at least looking at
>the inspector I can't see this. Is the wiki article still correct / the
>inspector not telling the truth ?
>
>Thanks,
>Tobias
>
>P.S. I'm using Wicket 1.5.8 btw
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org

EMAIL DISCLAIMER This email message and its attachments are confidential and may also contain copyright or privileged material. If you are not the intended recipient, you may not forward the email or disclose or use the information contained in it. If you have received this email message in error, please advise the sender immediately by replying to this email and delete the message and any associated attachments. Any views, opinions, conclusions, advice or statements expressed in this email message are those of the individual sender and should not be relied upon as the considered view, opinion, conclusions, advice or statement of this company except where the sender expressly, and with authority, states them to be the considered view, opinion, conclusions, advice or statement of this company. Every care is taken but we recommend that you scan any attachments for viruses.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: How important is detaching models really ?

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
I guess in more complex apps the UI elements end up with lots of
references to model objects so detaching does save a lot of memory and
it also makes transferring session data from one web server to another
(if required) in a multi server environment, much more efficient. I have
experienced the result of accidentally serializing an object graph with
megabytes of data that didn't use detach - ouch!

The other benefit of detaching is your model will expose updates to the
UI (if a redisplay occurred) that were made in other ORM sessions
(depending on your ORM). Keeping a non detached copy of the model object
will typically be like caching it in it's current state for most ORMs -
i.e. it can get stale

>-----Original Message-----
>From: tobi [mailto:tobias.gierke@code-sourcery.de]
>Sent: Thursday, 22 November 2012 9:10 PM
>To: users@wicket.apache.org
>Subject: How important is detaching models really ?
>
>Hi guys,
>
> From my understanding & experiments with Wicket's built-in session
>inspector , detaching models seems to just affect the size of the page
>store (and of course cut-down the amount of I/O required for
serializing
>the object graph). The session size shown on my pages is a constantly
>low value (<1k , we're storing nothing except the currently logged-in
>user).
>
>So it *seems* not detaching models has no effect on the (long-term)
>memory footprint of a Wicket application.
>
>According to
>https://cwiki.apache.org/WICKET/working-with-wicket-models.html , not
>detaching models should affect the session size but at least looking at
>the inspector I can't see this. Is the wiki article still correct / the
>inspector not telling the truth ?
>
>Thanks,
>Tobias
>
>P.S. I'm using Wicket 1.5.8 btw
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How important is detaching models really ?

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Check https://cwiki.apache.org/confluence/display/WICKET/Page+Storage
Only the last used page is stored temporarily in the http session.
Detaching the models decreases the used memory.


On Thu, Nov 22, 2012 at 12:09 PM, tobi <to...@code-sourcery.de>wrote:

> Hi guys,
>
> From my understanding & experiments with Wicket's built-in session
> inspector , detaching models seems to just affect the size of the page
> store (and of course cut-down the amount of I/O required for serializing
> the object graph). The session size shown on my pages is a constantly low
> value (<1k , we're storing nothing except the currently logged-in user).
>
> So it *seems* not detaching models has no effect on the (long-term) memory
> footprint of a Wicket application.
>
> According to https://cwiki.apache.org/**WICKET/working-with-wicket-**
> models.html<https://cwiki.apache.org/WICKET/working-with-wicket-models.html>, not detaching models should affect the session size but at least looking
> at the inspector I can't see this. Is the wiki article still correct / the
> inspector not telling the truth ?
>
> Thanks,
> Tobias
>
> P.S. I'm using Wicket 1.5.8 btw
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>