New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attribute converter not called successfully during EntityManager.refresh() call #2096
Comments
I think, that issue is in
Why |
The proposed code is a hypothetical example, since I can't share the actual code, but the code in question deals with sensitive information that needs to be flushed from arrays once persisted. Strings cannot be flushed, since they are immutable, so we use char[] in cases like this. The PreparedStatement and ResultSet API methods dealing with Reader and Writer support this use case without a trip through String. char[] is a standard supported type in JPA and we shouldn't really see a ClassCastException either way. Apart from this refresh() use case, char[] appears to behave correctly everywhere else. |
Yes |
At the database level, the fields are just varchar2 fields. Reader and Writer aren't types listed as supported by JPA, and I don't believe they could reasonably be used in entities either way given their unidirectional and single-use natures. |
But JPA/EclipseLink depends on JDBC. By default DB varchar2 field is fetched by ResultSet.getString(). This is why I'm mentioning JDBC. DB/JDBC delivers it as a |
What you're suggesting seems consistent with the Javadoc for converters. Our prior JPA implementation supports this, but we're hoping to switch to EclipseLink. Given the circumstances, and the state of this in the JPA/JDBC APIs, what is the preferred course of action for storing sensitive information which needs to be cleansed from memory after use in this library? The AttributeConverter API doesn't support the reader/writer paradigm, given that the Y (dbData) parameter must be usable for reading and writing. The only logical choice for this field type seems to be char[], but this seems a bit contradictory to the |
I verified JDBC calls if there is any chance to set/get |
You lost me a little bit on that last one. The JPA specification suggests that all basic types other than Id, Temporal, and Enumerated should be supported for conversion. At the JDBC driver level, It is definitely possible to work directly in char to service this use case using the getCharacterStream/setCharacterStream methods. Ignoring the desire to clear the arrays after use, which JPA claims no support for, char[] to String conversions to satisfy the terms of the specification's support for basic types would at least allow the type to be usable. |
Describe the bug
Attempting to call EntityManager's refresh method on an entity with an attribute converter leads to a ClassCastException.
To Reproduce
Create an entity like this:
And a converter like this:
And a PersistenceUnit like this:
Then, attempt to persist and refresh the entity like this test case:
Expected behavior
The attribute converter should be used for all operations related to the entity.
The text was updated successfully, but these errors were encountered: