java - 我需要将此休眠表表示为 mysql 表
问题描述
@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)等,但我不明白如何插入域父级。通常我在树应用程序中需要帮助,需要表示关系ip父子关系
解决方案
这只是表之间的正常关系。
CREATE TABLE DOMAIN
(
id BIGINT auto_increment,
-- other..
parent_id BIGINT
);
ALTER TABLE DOMAIN
ADD CONSTRAINT FOREIGN KEY (parent_id) REFERENCES DOMAIN(id);
推荐阅读
- html - Angular 从变量中读取 onblur 占位符值,而不是对其进行硬编码
- docker - 带有 Apache 容器和子域的 Docker 中的 Nginx 反向代理
- c++ - 为什么将字符串指针分配给字符串指针时会出现段错误?
- php - 我在 PHP 中使用 Curl 发出获取请求时遇到问题?SSL || 301
- c++ - C++ _Inout_updates_bytes_ 语法
- multithreading - 有没有办法在批处理文件中完成多线程或并行进程?
- java - Admob tagForChildDirectedTreatment()
- python - 在python中生成一组具有特定共同差异的小数点时出错
- typescript - 在 TypeScript 中测试具有模拟依赖项的类
- python - 如何清理具有字符串值的数据集?