使用 jpa 将对象持久化到对象中
Persist an object within an object with jpa
我有这个对象
@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;
}
我有这个对象
@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;
}