Top Description Methods
jakarta.persistence

public Interface AttributeConverter<X, Y>

Type Parameters
<X>
the target type, that is, the type of the entity attribute
<Y>
a basic type representing the type of the database column

Interface implemented by custom attribute converters. A converter is a class whose methods convert between:

A converted field or property is considered Basic, since, with the aid of the converter, its values can be represented as instances of a basic type.

A converter class must be annotated Converter or declared as a converter in the object/relational mapping descriptor. The value of autoApply determines if the converter is automatically applied to persistent fields and properties of the target type. The Convert annotation may be used to apply a converter which is declared autoApply=false, to explicitly disable conversion, or to resolve ambiguities when multiple converters would otherwise apply.

Note that the target type X and the converted basic type Y may be the same Java type.

See Also
Converter, Convert#converter

Method Summary

Modifier and TypeMethod and Description
public Y

Returns:

the converted data to be stored in the database column
convertToDatabaseColumn
(X
the entity attribute value to be converted
attribute
)

Converts the value stored in the entity attribute into the data representation to be stored in the database.

public X

Returns:

the converted value to be stored in the entity attribute
convertToEntityAttribute
(Y
the data from the database column to be converted
dbData
)

Converts the data stored in the database column into the value to be stored in the entity attribute.

Method Detail

convertToDatabaseColumnback to summary
public Y convertToDatabaseColumn(X attribute)

Converts the value stored in the entity attribute into the data representation to be stored in the database.

Parameters
attribute:X

the entity attribute value to be converted

Returns:Y

the converted data to be stored in the database column

convertToEntityAttributeback to summary
public X convertToEntityAttribute(Y dbData)

Converts the data stored in the database column into the value to be stored in the entity attribute.

Note that it is the responsibility of the converter writer to specify the correct dbData type for the corresponding column for use by the JDBC driver: i.e., persistence providers are not expected to do such type conversion.

Parameters
dbData:Y

the data from the database column to be converted

Returns:X

the converted value to be stored in the entity attribute