我有这个对象
@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
答案 0 :(得分:3)
您可以使用@Embeddable
和@Embedded
JPA注释。
@Entity
public class Cat {
@Id String name;
@Embedded
Fur fur;
}
@Embeddable
public class Fur {
String color1;
String color2;
}