在ElementCollection中不支持具有可嵌入MultiToOne引用的Embeddable吗?

时间:2013-02-25 15:47:21

标签: java hibernate jpa

我想按如下方式定义一个对象模型:

A包含一个X列表,每个X包含一个Y,每个Y指向一个B.我将其设置为A和B为Entity,而X和Y都是{{1 }}。 A包含一个类型为List of X的Embeddable。这些类的代码如下所示。

当要求Hibernate(3.6.10)使用@ElementCollection为此模型生成SQL时,我期望有三个表:A,B和一个从A到B的引用的集合表,包含A .id,B.id和用于保持列表顺序的订单列。相反,Hibernate给了我以下内容:

SchemaExport

请注意,集合表没有B.id的列,也没有应该存在的外键约束。在我看来,我应该支持我想要的模型。它是否有充分的理由(如果是这样,那是什么原因?),或者这是Hibernate或JPA中的错误/缺失功能?


作为一项实验,我折叠了我的create table CollectionOfB (A_ID bigint not null, embeddableAList_ORDER integer not null, primary key (A_ID, embeddableAList_ORDER)) create table EntityA (id bigint not null, primary key (id)) create table EntityB (id bigint not null, primary key (id)) alter table CollectionOfB add constraint FKFEABC9AD9AECF0BB foreign key (A_ID) references EntityA 关系,因此它只有一个级别(完全删除Y,将引用放在X的内部)。通过这种更改,架构会按照我的预期生成,因此Embeddable ElementCollection的{​​{1}}工作的基本思路是:

Embeddable

此外,如果我制作了不同的ManyToOne C,并将其定义为create table CollectionOfB (A_ID bigint not null, B_ID bigint, embeddableAList_ORDER integer not null, primary key (A_ID, embeddableAList_ORDER)) create table EntityA (id bigint not null, primary key (id)) create table EntityB (id bigint not null, primary key (id)) alter table CollectionOfB add constraint FKFEABC9AD9AED651B foreign key (B_ID) references EntityB alter table CollectionOfB add constraint FKFEABC9AD9AECF0BB foreign key (A_ID) references EntityA X( 一个{{1} X)它正确地引用了B.所以有两个Entity级别的想法,其中较低级别的Embeddable 工作。


ElementCollection

0 个答案:

没有答案
相关问题