Richard Zowalla created OPENJPA-3021:
----------------------------------------

             Summary: A converted attribute value is replaced by a bean proxy 
that loses state without a setter
                 Key: OPENJPA-3021
                 URL: https://issues.apache.org/jira/browse/OPENJPA-3021
             Project: OpenJPA
          Issue Type: Bug
            Reporter: Richard Zowalla
            Assignee: Richard Zowalla


A value of an attribute with an {{AttributeConverter}} is replaced by a 
generated bean proxy when its declared type is not a collection, map, date or 
calendar. The proxy is filled by calling the getters of the converted value and 
the matching setters of the proxy. State without a setter is lost.

Found by the Apache Syncope tests:

{code:java}
@Convert(converter = AuthModuleConfConverter.class)
@Lob
private AuthModuleConf jsonConf;   // AuthModuleConf is an interface
{code}

{code:java}
public class StaticAuthModuleConf implements AuthModuleConf {
    private String credentialCriteria;
    private final Map<String, String> users = new HashMap<>();   // getter only
    ...
}
{code}

The converter returns a {{StaticAuthModuleConf}} with the users from the 
column. The entity returns a {{StaticAuthModuleConf$proxy}} whose {{users}} map 
is empty.

Cause: {{SingleFieldManager.proxy()}} calls {{ProxyManager.newCustomProxy()}} 
for every {{JavaTypes.OBJECT}} field, also when the field has a converter. 
{{ProxyManagerImpl}} generates a subclass of the value's class and copies the 
value through its getter and setter pairs (or a copy constructor).

A converted value is opaque to the provider and should be kept as the converter 
returned it. Since the proxy is also what marks the field dirty when a setter 
of the value is called, change detection for such fields has to come from 
comparing the converted value at flush, as OPENJPA-3019 does for collections 
and maps converted as a whole.




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

Reply via email to