hibernate - 如何避免非规范化
问题描述
我有一个实体Category
和一个CategoryType
存在多对多关系的实体。
在第三个实体Request
中,我必须保存this的Category
and 。
我的伪代码是这样的:CategoryType
Request
Request
@Entity
class Request(
id: Long,
title: String,
description: String,
category_id: Long,
category_type_id: Long) {
@JoinColumn(name = "category_id", insertable = false, updatable = false)
@ManyToOne
category: Category
@JoinColumn(name = "category_type_id", insertable = false, updatable = false)
@ManyToOne
category: CategoryType
}
我认为以这种方式设计我的实体是一个坏主意,因为这两个 id (category_id
和category_type_id
)之间存在功能依赖(我猜),所以我不尊重第 3 范式。
所以我认为我可以创建一个表示多对多关系的实体,并将这个新实体的 id 保存在表中。
例如:
@Entity
class Request(
id: Long,
title: String,
description: String,
category_to_type_relation_id: Long) {
@JoinColumn(name = "category_to_type_relation_id", insertable = false, updatable = false)
@ManyToOne
category: CategoryToCatTypeRelation
}
@Entity
CategoryToCatTypeRelation(
id: Long,
category_id: Long,
category_type_id: Long)
您认为这可能是一个可行的解决方案吗?还是有更好的方法来避免非规范化?
解决方案
推荐阅读
- javascript - 在数组中映射数组
- excel - 计算任何列中出现值的行数
- javascript - FormGroup 的值未分配给 FormData
- bash - 如何根据特定列字段中出现 PATTERN 的连续次数来选择行?
- javascript - 使用 React Router 并不总是调用 useEffect
- typescript - 在 NGRX 中合并两个减速器
- c# - ServiceHub.Host.CLR.x64 不再工作
- java - 将opensrc Java项目发布到maven的简单方法
- sql - Postgres 从表中删除记录,保持最小值和最大值
- ios - 为什么以编程方式选择单元格后 - 单元格不是交互?