How to use custom type in JPA column?

后端 未结 2 1966
别那么骄傲
别那么骄傲 2021-01-18 02:54

I have a class:

public class Email {
  private String name;
  private String domain;
  public String toString() {
    return name + \"@\" + domain;
  }  
}
<         


        
2条回答
  •  误落风尘
    2021-01-18 03:44

    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.

提交回复
热议问题