jeudi 2 juillet 2015

How to emulate Attribute Converter in JPA <= 2.0?

JPA 2.1 introduced a nice new feature Attribute Converter - see an article e.g. here: http://ift.tt/1emBGDM

It allows you to have an attribute of a certain type and store it as something else in the database column. E.g. you have an entity with a field color which is of a type java.awt.Color but you want it to be stored in the database as a String, such as RED or WHITE.

@Entity
class Tag {
    String name;
    java.awt.Color color; // I want it to be stored as a different type
}

Is there a way of obtaining the similar result in JPA <= 2.0? I want to do it for a type which is not an enum.

Aucun commentaire:

Enregistrer un commentaire