0
@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>();

I know how to create table like: Create table domain(id int(10),and so on,but I dont understand how to insert Domain parent. And generally i need help in tree application,where need to represent relationsip parent-child

Andrzej Sydor
  • 1,373
  • 4
  • 13
  • 28

1 Answers1

0

It's just a normal relationship between tables.

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

ALTER TABLE DOMAIN
  ADD CONSTRAINT FOREIGN KEY (parent_id) REFERENCES DOMAIN(id);
Matheus
  • 3,058
  • 7
  • 16
  • 37