I have a class:
public class Email {
private String name;
private String domain;
public String toString() {
return name + \"@\" + domain;
}
}
<
Well, there are a number of ways:
annotate the Email class with @Embeddable, and have:
@Embedded
private Email email;
declare a custom value type - see here (using @Type)
You can make email an entity and it will work...but it's pretty ineficcient.
@Entity
public class Email {
...
}
Or you can swtich from Email to String and it will work. (What's the point of wrapping a String anyway?)
You can read this tutorial about custom user types in Hibernate (since you tagged it).
Or you can use @Embebbed as Bozho says.