【问题标题】:I need to represent this hibernate table to mysql table我需要将此休眠表表示为 mysql 表
【发布时间】:2019-09-07 10:25:15
【问题描述】:
@Entity
public class Domain {

    @Id
    private long id;

    /** The parent domain, can be null if this is the root domain. */
    @ManyToOne
    private Domain parent;

    /**
     * The children domain of this domain.
     *
     * This is the inverse side of the parent relation.
     *
     * <strong>It is the children responsibility to manage there parents children set!</strong>
     */
    @OneToMany(mappedBy = "parent")
    private Set<Domain> children = new HashSet<Domain>();

我知道如何创建如下表: 创建表域(id int(10)等,但我不明白如何插入域父级。 通常我在树应用程序中需要帮助,需要代表关系的父子关系

【问题讨论】:

  • 查找多对一关系并加入列。

标签: java spring hibernate hibernate-mapping


【解决方案1】:

这只是表之间的正常关系。

CREATE TABLE DOMAIN
  (
     id        BIGINT auto_increment,
     -- other..
     parent_id BIGINT
  );

ALTER TABLE DOMAIN
  ADD CONSTRAINT FOREIGN KEY (parent_id) REFERENCES DOMAIN(id);

【讨论】:

    猜你喜欢
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-04
    • 2013-06-01
    • 1970-01-01
    • 2016-09-07
    相关资源
    最近更新 更多