Skip to content

Commit 39b8e40

Browse files
authored
Remove hashCode() and equals() overrides + clean result entities annotation (#66)
Signed-off-by: Etienne Homer <[email protected]>
1 parent d92f178 commit 39b8e40

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

src/main/java/org/gridsuite/shortcircuit/server/entities/FaultResultEntity.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class FaultResultEntity {
3131
@GeneratedValue(strategy = GenerationType.AUTO)
3232
private UUID faultResultUuid;
3333

34-
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
34+
@ManyToOne(fetch = FetchType.LAZY)
3535
@Setter
3636
private ShortCircuitAnalysisResultEntity result;
3737

@@ -131,22 +131,6 @@ public void setFeederResults(List<FeederResultEntity> feederResults) {
131131
feederResults.stream().forEach(feederResultEntity -> feederResultEntity.setFaultResult(this));
132132
}
133133

134-
@Override
135-
public boolean equals(Object o) {
136-
if (this == o) {
137-
return true;
138-
}
139-
if (!(o instanceof FaultResultEntity)) {
140-
return false;
141-
}
142-
return faultResultUuid != null && faultResultUuid.equals(((FaultResultEntity) o).getFaultResultUuid());
143-
}
144-
145-
@Override
146-
public int hashCode() {
147-
return getClass().hashCode();
148-
}
149-
150134
public double getPositiveMagnitude() {
151135
return this.getFortescueCurrent() != null ? this.getFortescueCurrent().getPositiveMagnitude() : Double.NaN;
152136
}

src/main/java/org/gridsuite/shortcircuit/server/entities/FeederResultEntity.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ public class FeederResultEntity {
2828
@GeneratedValue(strategy = GenerationType.AUTO)
2929
private UUID feederResultUuid;
3030

31-
@ManyToOne(
32-
cascade = CascadeType.ALL,
33-
fetch = FetchType.LAZY
34-
)
31+
@ManyToOne(fetch = FetchType.LAZY)
3532
@JoinColumn(name = "fault_result_entity_fault_result_uuid")
3633
private FaultResultEntity faultResult;
3734

src/main/java/org/gridsuite/shortcircuit/server/entities/ShortCircuitAnalysisResultEntity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public class ShortCircuitAnalysisResultEntity {
3030
@Column
3131
private ZonedDateTime writeTimeStamp;
3232

33+
/*
34+
Bidirectional relation is not needed here and is done for performance
35+
https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/
36+
equals() and hashCode() methods are not overrided as the article above recommands it because we use a Set of FaultResultEntity
37+
and having a constant hashCode() causes performance issues.
38+
*/
3339
@OneToMany(mappedBy = "result", cascade = CascadeType.ALL, orphanRemoval = true)
3440
@Setter
3541
private Set<FaultResultEntity> faultResults;

src/test/java/org/gridsuite/shortcircuit/server/repositories/FaultResultRepositoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void tearDown() {
9999
void faultResultFilterTest(ShortCircuitAnalysisResultEntity resultEntity, List<ResourceFilter> resourceFilters, List<FaultResultEntity> faultList) {
100100
Page<FaultResultEntity> faultPage = shortCircuitAnalysisResultRepository.findFaultResultsPage(resultEntity, resourceFilters, Pageable.unpaged(), FaultResultsMode.BASIC);
101101
assertThat(faultPage.getContent()).extracting("fault.id").describedAs("Check if the IDs of the fault page are correct")
102-
.containsExactlyElementsOf(faultList.stream().map(faultResultEntity -> faultResultEntity.getFault().getId()).toList());
102+
.containsExactlyInAnyOrderElementsOf(faultList.stream().map(faultResultEntity -> faultResultEntity.getFault().getId()).toList());
103103
}
104104

105105
private Stream<Arguments> provideOrEqualsNestedFieldsFilters() {

0 commit comments

Comments
 (0)