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

ASF subversion and git services commented on OPENJPA-3023:
----------------------------------------------------------

Commit a2e9c6efe63eae61261bfaf159a53ee2ada0c192 in openjpa's branch 
refs/heads/master from Richard Zowalla
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=a2e9c6efe ]

[OPENJPA-3023] Cache the database value of a converted attribute (#226)

* [OPENJPA-3023] Cache the database value of a converted attribute

The data cache kept the value of an attribute with an AttributeConverter
as the Java object and handed the same objects to every persistence
context that loaded the instance from the cache, so a change made in
place in one context reached the others. The cache now holds the value
the converter writes to the database and runs the converter again when
the instance is loaded, so each persistence context gets its own copy.
This covers attributes converted as a whole and collections whose
elements are converted one by one. Arrays and dates returned by a
converter are copied on the way into and out of the cache.

* [OPENJPA-3023] Use pattern matching for the Date copy

> The data cache shares the value of a converted attribute between persistence 
> contexts
> -------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-3023
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-3023
>             Project: OpenJPA
>          Issue Type: Bug
>            Reporter: Richard Zowalla
>            Assignee: Richard Zowalla
>            Priority: Major
>
> With the data cache enabled, the value of an attribute with an 
> {{AttributeConverter}} is stored in the cache as the Java object, and the 
> same object is given to every persistence context that loads the instance 
> from the cache. A change made in place to such a value in one persistence 
> context is seen by the others, also when the transaction is rolled back.
> {code:java}
> @Convert(converter = ItemListConverter.class)
> private List<Item> items;
> {code}
> {code:java}
> em.getTransaction().begin();
> em.find(Entity.class, id).getItems().get(0).setName("changed");
> em.getTransaction().rollback();
> // new EntityManager
> em2.find(Entity.class, id).getItems().get(0).getName();   // "changed"
> {code}
> Cause: {{AbstractPCData.toData()}} copies a collection but keeps its 
> elements, and {{toNestedData()}} keeps a value that is not a proxy. On the 
> way back {{toNestedFields()}} returns the cached collection itself for 
> elements that are not entities, embeddables, dates or locales. The cache and 
> all persistence contexts share the element objects.
> For a converted attribute the cache can hold the converted database value and 
> run the converter when the instance is loaded from the cache, so every 
> persistence context gets its own copy.
> Related to the Apache Syncope report in the linked issue, where the elements 
> of a converted {{List<PlainAttr>}} are changed in place.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to