[ 
https://issues.apache.org/jira/browse/TAP5-2749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17703758#comment-17703758
 ] 

Volker Lamp commented on TAP5-2749:
-----------------------------------

Thank you for the detailed description and analysis, [~vbychkov]. Thank you 
also for the working example in your GitHub account.

Is there any chance I can motivate you transform your working example to a test 
case in the Tapestry code base? Happy to guide you through it should you get 
stuck. That way, we could be sure to never break it again, as we'd have the 
test run with every push.

To get started, fork [https://github.com/apache/tapestry-5], and take a look at 
the various test apps in {{tapestry-core/src/test}} and the units tests under 
{{{}tapestry-core/src/test/java{}}}.

> Incorrect behavior of getIfExists in EntityApplicationStatePersistenceStrategy
> ------------------------------------------------------------------------------
>
>                 Key: TAP5-2749
>                 URL: https://issues.apache.org/jira/browse/TAP5-2749
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-jpa
>    Affects Versions: 5.5.0, 5.8.2
>            Reporter: Vladimir V. Bychkov
>            Priority: Major
>
> +Error description+
> Test [project 
> demonstrates|https://github.com/bvfalcon/tapestry-entity-state-test] an error 
> which was added during optimization TAP5-2478.
> Methods 
> [get|https://github.com/apache/tapestry-5/blob/5.8.2/tapestry-core/src/main/java/org/apache/tapestry5/services/ApplicationStateManager.java#L57]
>  and 
> [getIfExists|https://github.com/apache/tapestry-5/blob/5.8.2/tapestry-core/src/main/java/org/apache/tapestry5/services/ApplicationStateManager.java#L67]
>  in ApplicationStateManager work different for JPA-Entities: first works 
> correct, second gives ClassCastException.
> +Reason+
> By invoking 
> [ApplicationStateManager.set|https://github.com/apache/tapestry-5/blob/5.8.2/tapestry-core/src/main/java/org/apache/tapestry5/services/ApplicationStateManager.java#L87]
>  method EntityApplicationStatePersistenceStrategy.set is used, which 
> [*transforms*|https://github.com/apache/tapestry-5/blob/5.8.2/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityApplicationStatePersistenceStrategy.java#L70]
>  instanceof Entity-class to instance of PersistedEntity Class.
> By Invoking ApplicationStateManager.get method 
> EntityApplicationStatePersistenceStrategy.get is used, which 
> [*transforms*|https://github.com/apache/tapestry-5/blob/5.8.2/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityApplicationStatePersistenceStrategy.java#L44]
>  instanceof PersistedEntity Class back to Entity-class. Therefore [this 
> code|https://github.com/bvfalcon/tapestry-entity-state-test/blob/master/src/main/java/org/apache/tapestry/components/Layout.java#L14]
>  works correct.
> By Invoking ApplicationStateManager.getIfExists method 
> SessionApplicationStatePersistenceStrategy.getIfExists is used 
> (SessionApplicationStatePersistenceStrategy is a superclass for 
> EntityApplicationStatePersistenceStrategy), which 
> [*casts*|https://github.com/apache/tapestry-5/blob/5.8.2/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java#L75]
>  instanceof PersistedEntity Class to Entity-class. This is incorrect and 
> gives ClassCastException in [this 
> code|https://github.com/bvfalcon/tapestry-entity-state-test/blob/master/src/main/java/org/apache/tapestry/components/Layout.java#L15].
> In other words, get makes back transformation, getIfExists - not. This is the 
> root of problem.
> +Fix proposal+
> The best solution IMHO will be [restore 
> getIfExists|https://github.com/apache/tapestry-5/blob/5.5.0/tapestry-core/src/main/java/org/apache/tapestry5/services/ApplicationStatePersistenceStrategy.java#L57]
>  in EntityApplicationStatePersistenceStrategy, may be with some optimizations 
> from TAP5-2478.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to