diff --git a/core/src/main/java/google/registry/model/domain/DomainHistory.java b/core/src/main/java/google/registry/model/domain/DomainHistory.java index 05f7c1cb0..a4e600a6c 100644 --- a/core/src/main/java/google/registry/model/domain/DomainHistory.java +++ b/core/src/main/java/google/registry/model/domain/DomainHistory.java @@ -196,7 +196,8 @@ public class DomainHistory extends HistoryEntry implements SqlEntity { @Access(AccessType.PROPERTY) @OneToMany( cascade = {CascadeType.ALL}, - fetch = FetchType.EAGER) + fetch = FetchType.EAGER, + orphanRemoval = true) @JoinColumn(name = "historyRevisionId", referencedColumnName = "historyRevisionId") @JoinColumn(name = "domainRepoId", referencedColumnName = "domainRepoId") @SuppressWarnings("unused") diff --git a/core/src/main/java/google/registry/model/ofy/ReplayQueue.java b/core/src/main/java/google/registry/model/ofy/ReplayQueue.java index 62c89c50d..c4c184a86 100644 --- a/core/src/main/java/google/registry/model/ofy/ReplayQueue.java +++ b/core/src/main/java/google/registry/model/ofy/ReplayQueue.java @@ -95,22 +95,21 @@ public class ReplayQueue { // Sort the changes into an order that will work for insertion into the database. jpaTm() .transact( - () -> { - changes.entrySet().stream() - .sorted(ReplayQueue::compareByPriority) - .forEach( - entry -> { - if (entry.getValue().equals(TransactionInfo.Delete.SENTINEL)) { - VKey vkey = VKey.from(entry.getKey()); - ReplaySpecializer.beforeSqlDelete(vkey); - jpaTm().delete(vkey); - } else { - ((DatastoreEntity) entry.getValue()) - .toSqlEntity() - .ifPresent(jpaTm()::put); - } - }); - }); + () -> + changes.entrySet().stream() + .sorted(ReplayQueue::compareByPriority) + .forEach( + entry -> { + if (entry.getValue().equals(TransactionInfo.Delete.SENTINEL)) { + VKey vkey = VKey.from(entry.getKey()); + ReplaySpecializer.beforeSqlDelete(vkey); + jpaTm().delete(vkey); + } else { + ((DatastoreEntity) entry.getValue()) + .toSqlEntity() + .ifPresent(jpaTm()::put); + } + })); } } } diff --git a/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java index 8414a91a9..319debaec 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java @@ -1087,13 +1087,6 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase { - HistoryEntry fromDatabase = tm().loadByEntity(domainHistory); + DomainHistory fromDatabase = tm().loadByEntity(domainHistory); assertAboutImmutableObjects() .that(fromDatabase) - .isEqualExceptFields( - domainHistory, "nsHosts", "domainTransactionRecords", "domainContent"); - assertAboutImmutableObjects() - .that(Iterables.getOnlyElement(fromDatabase.getDomainTransactionRecords())) - .isEqualExceptFields( - Iterables.getOnlyElement(domainHistory.getDomainTransactionRecords()), "id"); + .isEqualExceptFields(domainHistory, "domainContent"); }); }