I want to mapping a class to a primitive type
@Entity
@Table(name="PERSON")
public class Person implements Serializable {
...
private Email email = null;
...
@Column(name="email")
public Email getEmail() {
return email;
}
public void setEmail(Email email) {
this.email=email;
}
}
In this example I want to save the email like a String
I wish something like:
interface someInterface{
String getValue();
void setValue(String p);
}
Then if I implement this interface in Email it can be save and loaded transparently (I haven’t find something like this).
I don’t want to serialize the class
I use Email as a example, but I have in mind many other class, to little to be a whole entity.
Any idea?
JPA2.1 provides AttributeConverter which means that a field can be marked with a converter persisting it as, for example, a String. All JPA implementations have their own variant currently, but DataNucleus JPA provides the JPA2.1 feature already, see the foot of this page.