Since JPA 2.1 it is possible to use an AttributeConverter to map a JPA-attribute-domain value to a RDMBS-domain value. The documentation states these converters shouldn't be used for identifier attributes "because that gives non-portable code".
My question is: why that limitation on identifier attributes?
Reasons why it should not be a problem:
(1) If there is a clear separation of the concerns "manage enities, their relations and state" and "retrieve/store data from/into seom backend" are truly separated, such a limit makes no sense. If the concerns are not truly separated, the consequences should be for all attributes.
(2) Another concern could be that expressions that use identifiers or operators on identifiers have a different meaning or become invalid when the value gets converted. But the in the case of an identifier I assume that a converter is an invertible operation. It does not change the cardinality of values. Nor does it break an equality or non-equality relationship on both ends of the converter.
(3) I can imagine that there are (legacy) implementation details that do not make the separation perfect. In my opinion, that should never permeate into the API.
To be clear: I can and I did work around this problem, but I'm not satisfied by the explanation (if any) offered by the documentation. If there is a perfectly solid explanation for the limitation on identifier attributes I would like to learn that explanation.
Thanks in advance!
|