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:
http: //stackoverflow.com/questions/16269002/how-to-query-properties-of-an-entity-attribute-mapped-using-eclipselink-readtr
@Transformation(fetch = FetchType.EAGER, optional = false)
@ReadTransformer(transformerClass = MoneyReadTransformer.class)
@WriteTransformers({
@WriteTransformer(
transformerClass = MoneyCurrencyWriteTransformer.class,
column = @Column(name = "currency", nullable = false)),
@WriteTransformer(
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.