Richard Zowalla created OPENJPA-3023:
----------------------------------------

             Summary: 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


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