我有这个对象

@Entity
public class Cat {
  @Id String name;
  Fur fur;
}

public class Fur {
  String color1;
  String color2;
}


如何将其映射到:

 Name      Color1 Color2
+---------+------+------+
|SnowBall |red   |green |
+---------+------+------+
|Snowball2|white |black |
+---------+------+------+


我只有JPA 2.1

最佳答案

您可以使用@Embeddable@Embedded JPA批注。

@Entity
public class Cat {
  @Id String name;
  @Embedded
  Fur fur;
}

@Embeddable
public class Fur {
  String color1;
  String color2;
}

09-25 19:55