Hello again,

oops, I didn't see this message, sorry.
This here:
http://tapestry.apache.org/5.3/apidocs/src-html/org/apache/tapestry5/jpa/JpaModule.html
seems to indicate that the default for 
JpaSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED
is "true", which is part of why my changes do not make a difference.

Another part seems to be what you say, that I need to directly annotate an 
entity with @SessionState.

I've found this here:
http://tapestry.apache.org/5.3/apidocs/src-html/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.html#line.40

public class EntityApplicationStatePersistenceStrategy extends
        SessionApplicationStatePersistenceStrategy
{
    @Override
    public <T> T get(final Class<T> ssoClass, final ApplicationStateCreator<T> 
creator)
    {
        final Object persistedValue = getOrCreate(ssoClass, creator);

        if (persistedValue instanceof PersistedEntity)
        {
            final PersistedEntity persisted = (PersistedEntity) persistedValue;

            final Object restored = persisted.restore(entityManagerManager);

            // shall we maybe throw an exception instead?
            if (restored == null)
            {
                set(ssoClass, null);
                return (T) getOrCreate(ssoClass, creator);
            }

            return (T) restored;
        }

        return (T) persistedValue;
    }
}

Which tells me that entities contained in SSO annotated objects are basically 
out of luck, it seems.

So, is my method of creating a session state object containing multiple values 
not a good way to do this?
Or is it just that entities are used under-supported this way?

Regards,
Daniel P.

-----Ursprüngliche Nachricht-----
Von: Barry Books [mailto:trs...@gmail.com] 
Gesendet: Mittwoch, 18. März 2015 12:05
An: Tapestry users
Betreff: Re: Session Storage with Tapestry

If you are using Tapestry Hibernate it should just work if you put a Hibernate 
object into a SessionState variable. There is a configuration that contains the 
Hibernate entities so SessionState is able to store the primary key in the 
session and retrieve the object when needed. Services as well as 
pages/components should be able to lazy load from the SessionState object.

Assuming you are using Tapestry Hibernate then somehow the object in your 
SessionState is disconnected from the Hibernate session. If you turn on show 
sql you should see the object fetched evertime you go to a new page.
If you don't then something is wrong.



On Wed, Mar 18, 2015 at 5:21 AM, Poggenpohl, Daniel < 
daniel.poggenp...@isst.fraunhofer.de> wrote:

> Hello again,
>
> a slightly different topic as the last but with the same "undertones":
>
> I need a session storage where I store the currently logged on user.
> Reading about it in the documentation, they recommend using 
> @SessionState because my user is a complex object, also containing 
> lists of other entities.
>
> My user also is an entity in a database. So, when a user logs in, the 
> appropriate entity is retrieved from the database, an "AppSession" 
> object is created containing, among e.g. the time of login, the user 
> object. Is this the right way to do it? Or should I only store the ID in the 
> session?
>
> Now when the SessionState object is created, it can be used in any 
> other page or component using the same SessionState annotation and the same 
> type.
> Does it need to be the same name
> I'd say it doesn't, as I've not read otherwise.
>
> My user contains lazy collections of other entities. Every page of my 
> app contains the layout component which provides the login area and 
> serves to create the session object for the app, retrieving the user 
> entity in the process.
> A page containing the layout component itself contains another 
> component where these lazy collections are needed. The user logs in, 
> the SessionState object is created, the user entity is stored inside 
> the object. The page is requested again, and the component is 
> initialized/rendered. The component contains a reference to the 
> SessionState object. Inside the component, a tree should display objects of 
> the lazy collection.
> To do this, a service receives the user. The service tries to access 
> the lazy collection, but fails with a "failed to lazily initialize a 
> collection of role:".
>
> What I gather from this is, services don't operate within transactions?
>
> UPDATE: I tried to access the lazy collection from the component 
> itself, but the error was the same.
> Even from the page, the error still was present.
>
> This leads me to the point that I may be doing something wrong using 
> an entity in a session storage?
>
> Regards,
> Daniel Poggenpohl
>

Reply via email to