I'm trying to convert an application from Hibernate and running into difficulties with custom mappings.
I need to persist instances of Joda Money and the currency and amount need to be stored in separate database fields so a simple @Converter will not work.
It seems the only way to do this is with a @Transformation as seen here:
@Transformation(fetch = FetchType.EAGER, optional = false)
@ReadTransformer(transformerClass = MoneyReadTransformer.class)
transformerClass = MoneyCurrencyWriteTransformer.class,
column = @Column(name = "currency", nullable = false)),
transformerClass = MoneyAmountWriteTransformer.class,
column = @Column(name = "amount", nullable = false))
private Money price;
Implementing the FieldTransformer for the @WriteTransformer seems straightforward but I can't find any examples of how to implement AttributeTransformer for reconstructing the entity from the database fields.
Can anyone point me to an example AttributeTransformer implementation, I've spent a fair bit of time researching this but drawn a blank so far.