diff --git a/core/src/main/java/google/registry/model/domain/token/PackagePromotion.java b/core/src/main/java/google/registry/model/domain/token/PackagePromotion.java index f0db57fd4..3b209ede3 100644 --- a/core/src/main/java/google/registry/model/domain/token/PackagePromotion.java +++ b/core/src/main/java/google/registry/model/domain/token/PackagePromotion.java @@ -29,6 +29,8 @@ import java.util.Optional; import javax.annotation.Nullable; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import org.hibernate.annotations.Columns; import org.hibernate.annotations.Type; @@ -41,7 +43,9 @@ import org.joda.time.DateTime; public class PackagePromotion extends ImmutableObject implements Buildable { /** An autogenerated identifier for the package promotion. */ - @Id long packagePromotionId; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + long packagePromotionId; /** The allocation token string for the package. */ @Column(nullable = false) diff --git a/core/src/test/java/google/registry/model/domain/token/PackagePromotionTest.java b/core/src/test/java/google/registry/model/domain/token/PackagePromotionTest.java index 3f02b20ef..a856ddbc9 100644 --- a/core/src/test/java/google/registry/model/domain/token/PackagePromotionTest.java +++ b/core/src/test/java/google/registry/model/domain/token/PackagePromotionTest.java @@ -15,8 +15,9 @@ package google.registry.model.domain.token; import static com.google.common.truth.Truth.assertThat; +import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects; +import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.testing.DatabaseHelper.createTld; -import static google.registry.testing.DatabaseHelper.loadByEntity; import static google.registry.testing.DatabaseHelper.persistResource; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -57,16 +58,18 @@ public class PackagePromotionTest extends EntityTestCase { .build()); PackagePromotion packagePromotion = - persistResource( - new PackagePromotion.Builder() - .setToken(token) - .setPackagePrice(Money.of(CurrencyUnit.USD, 10000)) - .setMaxCreates(40) - .setMaxDomains(10) - .setNextBillingDate(DateTime.parse("2011-11-12T05:00:00Z")) - .build()); + new PackagePromotion.Builder() + .setToken(token) + .setPackagePrice(Money.of(CurrencyUnit.USD, 10000)) + .setMaxCreates(40) + .setMaxDomains(10) + .setNextBillingDate(DateTime.parse("2011-11-12T05:00:00Z")) + .build(); - assertThat(loadByEntity(packagePromotion)).isEqualTo(packagePromotion); + jpaTm().transact(() -> jpaTm().put(packagePromotion)); + assertAboutImmutableObjects() + .that(jpaTm().transact(() -> PackagePromotion.loadByTokenString("abc123")).get()) + .isEqualExceptFields(packagePromotion, "packagePromotionId"); } @Test diff --git a/core/src/test/java/google/registry/tools/UpdatePackagePromotionCommandTest.java b/core/src/test/java/google/registry/tools/UpdatePackagePromotionCommandTest.java index db0506955..e68f04470 100644 --- a/core/src/test/java/google/registry/tools/UpdatePackagePromotionCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdatePackagePromotionCommandTest.java @@ -58,7 +58,7 @@ public class UpdatePackagePromotionCommandTest .setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z")) .setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z")) .build(); - persistResource(packagePromotion); + jpaTm().transact(() -> jpaTm().put(packagePromotion)); } @Test diff --git a/db/src/main/resources/sql/schema/db-schema.sql.generated b/db/src/main/resources/sql/schema/db-schema.sql.generated index b48a6f75a..34bbe0906 100644 --- a/db/src/main/resources/sql/schema/db-schema.sql.generated +++ b/db/src/main/resources/sql/schema/db-schema.sql.generated @@ -492,7 +492,7 @@ ); create table "PackagePromotion" ( - package_promotion_id int8 not null, + package_promotion_id bigserial not null, last_notification_sent timestamptz, max_creates int4 not null, max_domains int4 not null,