A converter supplies application-defined logic for translating a domain value to a persistence representation and back. JPA converters provide a standardized extension point for customizing how property values are stored and loaded. section 6.0 section 6.3.2
Implement javax.persistence.AttributeConverter<X, Y>, where X is the domain type and Y is the database-facing Java type. Mark the implementation with @Converter. The convertToDatabaseColumn method translates X to Y for storage; convertToEntityAttribute reconstructs X from Y when loading. section 6.3.2
Store a monetary amount as a string
A MonetaryAmount combines a value and a currency. A converter can map it to a String such as “11.23 USD” for a VARCHAR column and reconstruct the amount when it is loaded. This lets the application introduce multiple currencies before the database has separate amount and currency columns. section 6.3.2
Apply the converter to the buyNowPrice property with @Convert and map the resulting value to the PRICE column. section 6.3.2
When the schema gains separate amount and currency columns, MonetaryAmount can instead become an @Embeddable mapped to those columns. Converters can be selectively enabled or disabled during a partial schema migration. section 6.3.2
Convert a nested value
A Zipcode converter can store a zipcode as a string and choose a concrete subtype when loading it. An @Convert annotation on an embedded address can target the nested property with attributeName = "city.zipcode". section 6.3.2
Converters can also adapt legacy temporal values, for example by converting a java.sql temporal value to a plain java.util.Date or giving a loaded Calendar a non-default time zone. Hibernate’s native UserType API is another, lower-level way to write an adapter. section 6.3.1 section 6.4



