gpt4 book ai didi

java - JPA Embeddable 可以具有 ElementCollection 属性

转载 作者:行者123 更新时间:2023-12-02 06:13:02 26 4
gpt4 key购买 nike

JPA ElementCollection Embeddable 可以具有 ElementCollection List Embeddable 属性吗?

  @Entity
class Person {
@ElementCollection
private List<Address> addressList;
}


@Embeddable
public class Address {
private String city;
private String state;
private String countary;
@ElementCollection
private List<Phone> phones;

...
}
@Embeddable
public class Phone {
private String type;
private String areaCode;
private String number;
...
}

最佳答案

是的,你可以拥有它,如果你尝试你的配置,你将会得到类似的东西。

http://postimg.org/image/pc0f3cxbp/

可嵌入类型还可以与 JPA 允许的其他实体具有集合关系。

取自规范 JSR317

An embeddable class may be used to represent the state of another embeddable class.

An embeddable class (including an embeddable class within another embeddable class) may contain a collection of a basic type or other embeddable class.

An embeddable class may contain a relationship to an entity or collection of entities. Since instances of embeddable classes themselves have no persistent identity, the relationship from the referenced entity is to the entity that contains the embeddable instance(s) and not to the embeddable itself.

An embeddable class that is used as an embedded id or as a map key must not contain such a relationship

更新

根据您的问题,如果嵌入物可以包含嵌入物列表,这是可能的,并且可以按照此答案中的图片建议完成,但是关于是否 ElementCollection 可以包含具有另一个元素集合的嵌入物答案是

尝试这样做会导致。

Mapping contains an embeddable "examples.model.Address" with a prohibited mapping "phones", element collections may not contain embeddables with element collection mappings

关于java - JPA Embeddable 可以具有 ElementCollection<Embeddable> 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21719164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com