当我将Hibernat设置为hbmddl = create
父实体就是这一个 - 基类没有冲突的属性。
@Entity
@Table(name = "attributes_text_values")
@PrimaryKeyJoinColumn(name = "attributeValue_id", referencedColumnName = "id")
@DiscriminatorValue("TEXT")
public class TextAttributeValue extends AttributeValue {
@OneToMany(mappedBy = "attributeValue", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
private List<TextAttributeValueLabel> labels;
然后相关的类定义如下:
@Entity
@Table(name = "attributes_text_value_labels")
public class TextAttributeValueLabel extends AbstractAuditableEntity{
@ManyToOne
private AttributeValue attributeValue;
启动时我在日志中收到错误:
22:23:40.640 DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger 109 logStatement - alter table attributes_text_value_labels drop foreign key FK_7yali4vrura8hbmpj2h6gyf4n
22:23:40.653 DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger 109 logStatement - alter table attributes_text_value_labels drop foreign key FK_jn9v2dt1vcr1bf14p48wxgpnv
22:23:40.667 DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger 109 logStatement - alter table attributes_text_value_labels drop foreign key FK_35dt165s920hrh03kupm0b9n7
22:23:40.683 DEBUG org.hibernate.engine.jdbc.spi.SqlStatementLogger 109 logStatement - alter table attributes_text_value_labels drop foreign key FK_35dt165s920hrh03kupm0b9n7
22:23:40.694 ERROR org.hibernate.tool.hbm2ddl.SchemaExport 426 perform - HHH000389: Unsuccessful: alter table attributes_text_value_labels drop foreign key FK_35dt165s920hrh03kupm0b9n7
尝试再次添加外键时出现类似错误。
我注意到它出于某种原因试图两次降低FK。
有谁知道为什么以及如何解决它?
答案 0 :(得分:0)
多对一方必须是TextAttributeValue
类型,因为它代表TextAttributeValue
和TextAttributeValueLabel
之间的双向关联:
@Entity
@Table(name = "attributes_text_value_labels")
public class TextAttributeValueLabel extends AbstractAuditableEntity{
@ManyToOne
private TextAttributeValue attributeValue;
如果要在TextAttributeValueLabel
中管理抽象类型集合,可以在AttributeValue
实体上定义一对多方面。但它看起来不是你的情况。