我使用:Hibernate的DDL错误@JoinTable主键与@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)
这是一个bug(EclipseLink的生成正确PK)?
有没有办法(或解决方法)让Hibernate生成正确的PK?
请注意,我不想在我自己的上生成DDL。
感谢
为什么连接表*不包含订单的PK?一个列表可以有一个元素的重复。 –
没错,但我不想重复PERSON_ID,ACCOUNT_ID。也许它应该是'主键(PERSON_ID,ACCOUNT_ID,PERSON_ORDER)'? –
或者我应该添加一个独特的限制条件。 –