[
https://issues.apache.org/jira/browse/TAP5-2749?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Vladimir V. Bychkov updated TAP5-2749:
--------------------------------------
Affects Version/s: 5.8.2
> 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)