jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
203 stars 59 forks source link

Holes in the specification of attribute converters #509

Closed gavinking closed 1 year ago

gavinking commented 1 year ago

AFAICT, nowhere does the spec say how to determine the target type of an AttributeConverter.

UPDATE: in fact, the spec as written is not even clear at all as to what is a legal "target" type, and what is a legal converted type.

gavinking commented 1 year ago

Something else I ran into: in the javadoc it's lightly-implied that @Convert with no converter and no disableConversion may be used to apply a non-auto-apply converter, which looks useful and totally makes sense.

But then this is contradicted (clarified?) in the spec which says that in fact the behavior in this case is undefined.

I would formalize what is implied by the Javadoc. Annotating a field @Convert should look for a suitable converter and apply it. There's no need to explicitly specify the converter class unless there is an ambiguity.

gavinking commented 1 year ago

I've found another hole here. The spec mentions three cases for use of @Convert:

  1. "applied to a basic attribute or to an element collection of basic type"
  2. "applied to an embedded attribute or to a map collection attribute whose key or value is of embeddable type"
  3. " applied to an entity class that extends a mapped superclass"

and it says:

What about:

  1. Can @Convert be used with non-map collections of embeddables?
  2. For a map value of basic type can/must "value" be used?