java - 将 BaseEntity 用于 JPA 实体时,Sonar 中的“等于错误”
问题描述
我们正在为 JPA 实体使用 BaseEntity 类,它实现了如下的 equals 方法。
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null) {
return false;
}
if (getClass() != object.getClass()) {
return false;
}
BaseEntity other = (BaseEntity) object;
if (this.getId() == null && other.getId() == null) {
return false;
}
if (this.getId() != other.getId() && (this.getId() == null || !this.id.equals(other.id))) {
return false;
}
return true;
}
对于扩展 BaseEntity Sonar 的所有类,显示代码异味问题。
Override the "equals" method in this class.
我们应该如何处理?
解决方案
推荐阅读
- powershell - Powershell导航到特定目录
- google-analytics - 如何使用 Google Analytics API 启用广告功能?
- excel - Power Query 表达式错误:“记录”类型的值无法转换为“文本”类型
- .net-core - 如何翻译 Blazor 组件和 App.razor 中的字符串?
- python - i = self.pos[0] 说 TypeError: 'int' object is not subscriptable,我的代码的第 18 行和第 19 行
- django - 如何从列表中提取 JSON 值并以 django 模型形式呈现?
- sas - 如何在 SAS 中使用 WHERE 函数?
- hangouts-chat - 使用 Google Chat API 创建的 Bot 的 URI/超链接
- git - Rubocop:从命令行给出的列表中排除文件
- python - 使用协程和函数作为 python 中的方法保持 SOLID 和 DRY