Hi,

yes, I've read http://tapestry.apache.org/persistent-page-data.html. I just 
couldn't wrap my head around it before because I always thought storing data 
between requests automatically meant storing it in a client-side cookie or 
something like that. This has been cleared up, thank you for that.

JPA.ENTITY was a really stupid shorthand for JpaPersistenceConstants.ENTITY 
because I was too lazy at that moment, so sorry for that.

> This is up to the servlet container, not Tapestry.

Sometimes I feel that such things would be clear to me if I'd read some sort of 
Web Applications for Starters or something like that. I've dabbled in web 
development before, but somehow I've yet to find a good primer for the basics.
Anyone know a good book for web application/development?

>> - should I rather persist primitive type (e.g. int) entity ID's in the 
>> page or can I use the entities themselves?

> It depends on the usage. If you just want to store just a reference to the 
> object, not storing changes that
> weren't propagated to the database yet, 

Something's missing there, I presume?

> Anyway, the recommended approach is to *not* use @Persist unless you've left 
> with no other option. The 
> best way to pass an entity reference from one page to another or to an event 
> link is using the context, as 
> explained here: http://tapestry.apache.org/page-navigation.html. This avoid 
> usage of HttpSession, lowering the 
> memory usage and avoiding problems when the user uses multiple tabs

I'll look into unpersisting most of my persisted page data then when given the 
time, then.

Regards,
Daniel P.

-----Ursprüngliche Nachricht-----
Von: Thiago H de Paula Figueiredo [mailto:thiag...@gmail.com] 
Gesendet: Mittwoch, 18. März 2015 13:49
An: Tapestry users
Betreff: Re: Memory Footprint in Tapestry

On Wed, 18 Mar 2015 05:21:51 -0300, Poggenpohl, Daniel 
<daniel.poggenp...@isst.fraunhofer.de> wrote:

> Hello,

Hi!

Have you seen http://tapestry.apache.org/persistent-page-data.html?

> For example, I have a page and database entities used in the page. 
> What is the difference in using @Persist for these entities? If I 
> don't use @Persist, are these objects only stored server-side in the VM?

Non-annotated fields are kept during the request and thrown away when it 
finishes. Where it's stored depends on the value attribute of @Persist for that 
given field. With @Persist(PersistenceConstants.SESSION), it's basically 
putting the field into the HttpSession with an attribute name crafted to be 
unique among pages and components, avoiding mix-ups. With 
@Persist(PersistenceConstants.CLIENT), it's stored on the client, as a query 
parameter or hidden field. With @Persist(PersistenceConstants.FLASH), it's 
stored in the session, but automatically removed after it's read in another 
request. This information was taken from here:  
http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/PersistenceConstants.html.
If you're using tapestry-hibernate, you can use 
@Persist(HibernatePersistenceConstants.ENTITY). If you're using tapestry-jpa, 
you can use @Persist(JpaPersistenceConstants.ENTITY). These last two store just 
class name and id, not the entity object itself.

> If I use @Persist,
> - where is the data stored on the client side? In a cookie? Could I 
> read this data?

See above.

> - What does using SESSION lead to? Creating a session cookie?

This is up to the servlet container, not Tapestry.

> - should I rather persist primitive type (e.g. int) entity ID's in the 
> page or can I use the entities themselves?

It depends on the usage. If you just want to store just a reference to the 
object, not storing changes that weren't propagated to the database yet,

> - Does JPA.ENTITY automatically store only the entity ID's in the 
> cookie between requests?

I'm not sure what you mean by JPA.ENTITY here. Anyway, Tapestry itself, 
out-of-the-box, doesn't use cookies to store @Persist'ed fields, but you can 
use Or use the ENTITY persistent field strategies explained above. In addition, 
you can also implement your own PersistentFieldStrategy to store @Persist'ed 
fields in any way you want: session, database, cookie, by id, whole object ...

> Should I rather use entity ID's or entities? If entities are used in 
> multiple methods, they always needed to loaded via DAO. After the 
> first query the objects probably are cached to speed up later ones, 
> aren't they?

Tapestry itself doesn't cache your objects unless you explicitly ask. You can 
use the @Cached annotation in a page, component and mixin method and the method 
return value will be cached on first call in a given request, with subsequent 
method calls in the same request just returning the cached values.

Anyway, the recommended approach is to *not* use @Persist unless you've left 
with no other option. The best way to pass an entity reference from one page to 
another or to an event link is using the context, as explained
here: http://tapestry.apache.org/page-navigation.html. This avoid usage of 
HttpSession, lowering the memory usage and avoiding problems when the user uses 
multiple tabs.

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to