首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要将这个hibernate表表示为mysql表

我需要将这个hibernate表表示为mysql表
EN

Stack Overflow用户
提问于 2019-09-07 18:25:15
回答 1查看 51关注 0票数 0
代码语言:javascript
复制
@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>();

我知道如何创建表格,如: create table domain(id int(10),依此类推,但我不知道如何插入父域名。通常我需要树应用程序的帮助,在树应用程序中需要表示父子关系

EN

回答 1

Stack Overflow用户

发布于 2019-09-09 08:54:18

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

代码语言:javascript
复制
CREATE TABLE DOMAIN
  (
     id        BIGINT auto_increment,
     -- other..
     parent_id BIGINT
  );

ALTER TABLE DOMAIN
  ADD CONSTRAINT FOREIGN KEY (parent_id) REFERENCES DOMAIN(id);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57832807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档