生成DDL

时间:2015-12-10 08:34:20

标签: java hibernate jpa orm ddl

我正在将我的项目迁移到Hibernate 5.0。我们使用生成的DDL有多种原因,因此DDL应该与以前完全相同。除了@ForeignKey @JoinColumn关系@OneToMany中的@Entity @Table(name = "CHILD", indexes = { @Index(columnList = "NAME", name = "IDX_CHILD_NAME") }, uniqueConstraints = { @UniqueConstraint(columnNames = "NAME", name = "UK_CHILD_NAME") }) @SequenceGenerator(allocationSize = 1, name = "CHILD_ID_GENERATOR", sequenceName = "CHILD_ID_SEQ") public class Child { @Id @GeneratedValue(generator = "CHILD_ID_GENERATOR", strategy = SEQUENCE) @Column(name = "ID") private Long id; @Column(name = "NAME") private String name; @OneToMany() @JoinColumn(name = "CHILD_ID", foreignKey = @ForeignKey(name = "FK_CHILD_PET")) private List<Pet> pets; } 名称之外,我的大部分内容都有效。

我有一个子实体:

@Entity
@Table(name = "PET", indexes = { @Index(columnList = "NAME", name = "IDX_PET_NAME") }, uniqueConstraints = { @UniqueConstraint(columnNames = "NAME", name = "UK_PET_NAME") })
@SequenceGenerator(allocationSize = 1, name = "PET_ID_GENERATOR", sequenceName = "PET_ID_SEQ")
public class Pet {
    @Id
    @GeneratedValue(generator = "PET_ID_GENERATOR", strategy = SEQUENCE)
    @Column(name = "ID")
    private Long id;

    @Column(name = "NAME")
    private String name;



}

和宠物实体:

alter table PET add constraint FKaxwc707slbsrp6vgxyyydrvcy foreign key (CHILD_ID) references CHILD

但是当我尝试生成DDL时,我得到以下声明:

@OneToMany()
@org.hibernate.annotations.ForeignKey(name = "FK_CHILD_PET")
@JoinColumn(name = "CHILD_ID")
private List<Pet> pets;

当我更改注释以包含Hibernate的弃用的ForeignKey时,如此

alter table PET add constraint FK_CHILD_PET foreign key (CHILD_ID) references CHILD

我确实得到了所需的输出

[['C'], ['B'], ['A'], ['C', 'B'], ['B', 'A'], ['A', 'C']]

但我想删除那个已弃用的Hibernate ForeignKey注释。

有什么建议吗?

我还在示例项目中包含了上述代码: https://github.com/vdmc/generate-ddl-example.git

0 个答案:

没有答案