Hibernate DDL 错误的@JoinTable Primary Key with @OrderColumn

Hibernate DDL wrong @JoinTable Primary Key with @OrderColumn

我正在使用:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.3.10.Final</version>
    <scope>provided</scope>
</dependency>

我有这个实体:

@Entity
public class Person extends Subject
{
    ...

    @ManyToMany
    @JoinTable(name = "PERSON_ACCOUNT", joinColumns = @JoinColumn(name = "PERSON_ID") , inverseJoinColumns = @JoinColumn(name = "ACCOUNT_ID") )
    @OrderColumn(name = "PERSON_ORDER")
    private List<Account> accountList = new ArrayList<>();

    ...
}

Hibernate 生成这个 SQL:

create table PERSON_ACCOUNT (PERSON_ID bigint not null, ACCOUNT_ID bigint not null, PERSON_ORDER integer not null, primary key (PERSON_ID, PERSON_ORDER)) ENGINE=InnoDB

但是,IMO,PK 不正确。
PK应该是:

primary key (PERSON_ID, ACCOUNT_ID)

这是错误吗(EclipseLink 生成正确的 PK)?

有没有办法(或解决方法)让 Hibernate 生成正确的 PK?

请注意我不想自己生成 DDL

谢谢

使用顺序列的列表的联接 table 的 PK 应始终将 PERSON_ORDER 作为 PK 的一部分,因为 List 应该允许重复.

如果您不想要重复的 PERSON_ID, ACCOUNT_ID 组合,那么您就不要使用允许重复的列表...即选择一个 List 实现不允许它们(SortedSet?)或按照您所说的唯一约束进行操作(但这仅在持续存在时生效,因此可能不是最有效的)。

说 EclipseLink 生成正确的 PK 是不正确的,因为它是完全错误的...它禁止复制,因此对大多数 Lists 没有用(即使字段是一个列表)。