簡體   English   中英

我需要將這個休眠表表示到 mysql 表

[英]I need to represent this hibernate table to mysql table

@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),等等,但我不明白如何插入域父級。通常我需要樹應用程序的幫助,需要表示父子關系的地方

這只是表之間的正常關系。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM