From e8cc79534de71671361a2f9a0c2c90efc2ef89a5 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Mon, 23 Jun 2025 18:48:34 -0400 Subject: [PATCH 1/3] introduce lombok usage in integrationTest to decrease boilerplate --- build.gradle.kts | 15 +++++++++++---- gradle/libs.versions.toml | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 21d4e549..d50b2cf9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,6 +53,10 @@ val integrationTestImplementation: Configuration by configurations.getting { extendsFrom(configurations.implementation.get()) } val integrationTestRuntimeOnly: Configuration by configurations.getting { extendsFrom(configurations.runtimeOnly.get()) } +val integrationTestCompileOnly: Configuration by + configurations.getting { extendsFrom(configurations.compileOnly.get()) } +val integrationTestAnnotationProcessor: Configuration by + configurations.getting { extendsFrom(configurations.annotationProcessor.get()) } val integrationTestTask = tasks.register("integrationTest") { @@ -110,7 +114,7 @@ spotless { tasks.check { dependsOn(tasks.spotlessApply) } tasks.withType().configureEach { - options.compilerArgs.addAll(listOf("-Xlint:all", "-Werror")) + options.compilerArgs.addAll(listOf("-Xlint:all,-serial,-processing", "-Werror")) when (this) { tasks.compileJava.get() -> options.errorprone { @@ -138,15 +142,18 @@ buildConfig { dependencies { testImplementation(libs.bundles.test.common) testImplementation(libs.mockito.junit.jupiter) - testRuntimeOnly("org.junit.platform:junit-platform-launcher") + testRuntimeOnly(libs.junit.platform.launcher) testCompileOnly(libs.checker.qual) integrationTestImplementation(libs.bundles.test.common) - @Suppress("UnstableApiUsage") integrationTestImplementation(libs.hibernate.testing) { exclude(group = "org.apache.logging.log4j", module = "log4j-core") } - integrationTestRuntimeOnly("org.junit.platform:junit-platform-launcher") + integrationTestImplementation(libs.lombok) + integrationTestRuntimeOnly(libs.junit.platform.launcher) + + integrationTestCompileOnly(libs.lombok) + integrationTestAnnotationProcessor(libs.lombok) api(libs.jspecify) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2e091a53..abc2e3e3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -24,6 +24,7 @@ slf4j-api = "2.0.16" logback-classic = "1.5.16" mockito = "5.16.0" checker-qual = "3.49.1" +lombok = "1.18.38" plugin-spotless = "7.0.2" plugin-errorprone = "4.1.0" @@ -33,6 +34,7 @@ plugin-ktfmt = "0.54" [libraries] junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" } +junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" } assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } nullaway = { module = "com.uber.nullaway:nullaway", version.ref = "nullaway" } jspecify = { module = "org.jspecify:jspecify", version.ref = "jspecify" } @@ -44,6 +46,7 @@ sl4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j-api" } logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback-classic" } mockito-junit-jupiter = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" } checker-qual = { module = "org.checkerframework:checker-qual", version.ref = "checker-qual" } +lombok = { module = "org.projectlombok:lombok", version.ref = "lombok" } [bundles] test-common = ["junit-jupiter", "assertj", "logback-classic"] From b323910f27f387195347b6ca728936d13b6446dd Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Sun, 29 Jun 2025 08:04:20 -0400 Subject: [PATCH 2/3] make "-Xlint:all -Werror" only applicable to production code, not testing code --- build.gradle.kts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d50b2cf9..fff43fed 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -114,14 +114,15 @@ spotless { tasks.check { dependsOn(tasks.spotlessApply) } tasks.withType().configureEach { - options.compilerArgs.addAll(listOf("-Xlint:all,-serial,-processing", "-Werror")) when (this) { - tasks.compileJava.get() -> + tasks.compileJava.get() -> { + options.compilerArgs.addAll(listOf("-Xlint:all", "-Werror")) options.errorprone { disableWarningsInGeneratedCode = true option("NullAway:AnnotatedPackages", "com.mongodb.hibernate") error("NullAway") } + } else -> options.errorprone.isEnabled = false } } From 6ffc4a5709f685a588c1ab64f640d612042d652c Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Fri, 4 Jul 2025 11:17:01 -0400 Subject: [PATCH 3/3] resolve conflict with latest main branch; make use of @Builder lombok feature --- .../ArrayAndCollectionIntegrationTests.java | 257 +++++++----------- .../EmbeddableIntegrationTests.java | 135 ++------- ...ctAggregateEmbeddableIntegrationTests.java | 223 +++++---------- 3 files changed, 191 insertions(+), 424 deletions(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java index 868bb9c8..e2bde795 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java @@ -37,6 +37,9 @@ import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; import org.bson.BsonDocument; import org.bson.types.ObjectId; import org.hibernate.MappingException; @@ -76,35 +79,37 @@ public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) { @Test void testArrayAndCollectionValues() { - var item = new ItemWithArrayAndCollectionValues( - 1, + var item = ItemWithArrayAndCollectionValues.builder() + .id(1) // TODO-HIBERNATE-48 sprinkle on `null` array/collection elements - new byte[] {2, 3}, - new char[] {'s', 't', 'r'}, - new int[] {5}, - new long[] {Long.MAX_VALUE, 6}, - new double[] {Double.MAX_VALUE}, - new boolean[] {true}, - new Character[] {'s', 't', 'r'}, - new Integer[] {7}, - new Long[] {8L}, - new Double[] {9.1d}, - new Boolean[] {true}, - new String[] {"str"}, - new BigDecimal[] {BigDecimal.valueOf(10.1)}, - new ObjectId[] {new ObjectId("000000000000000000000001")}, - new StructAggregateEmbeddableIntegrationTests.Single[] { + .bytes(new byte[] {2, 3}) + .chars(new char[] {'s', 't', 'r'}) + .ints(new int[] {5}) + .longs(new long[] {Long.MAX_VALUE, 6}) + .doubles(new double[] {Double.MAX_VALUE}) + .booleans(new boolean[] {true}) + .boxedChars(new Character[] {'s', 't', 'r'}) + .boxedInts(new Integer[] {7}) + .boxedLongs(new Long[] {8L}) + .boxedDoubles(new Double[] {9.1d}) + .boxedBooleans(new Boolean[] {true}) + .strings(new String[] {"str"}) + .bigDecimals(new BigDecimal[] {BigDecimal.valueOf(10.1)}) + .objectIds(new ObjectId[] {new ObjectId("000000000000000000000001")}) + .structAggregateEmbeddables(new StructAggregateEmbeddableIntegrationTests.Single[] { new StructAggregateEmbeddableIntegrationTests.Single(1) - }, - List.of('s', 't', 'r'), - List.of(5), - List.of(Long.MAX_VALUE, 6L), - List.of(Double.MAX_VALUE), - List.of(true), - List.of("str"), - List.of(BigDecimal.valueOf(10.1)), - List.of(new ObjectId("000000000000000000000001")), - List.of(new StructAggregateEmbeddableIntegrationTests.Single(1))); + }) + .charsCollection(List.of('s', 't', 'r')) + .intsCollection(List.of(5)) + .longsCollection(List.of(Long.MAX_VALUE, 6L)) + .doublesCollection(List.of(Double.MAX_VALUE)) + .booleansCollection(List.of(true)) + .stringsCollection(List.of("str")) + .bigDecimalsCollection(List.of(BigDecimal.valueOf(10.1))) + .objectIdsCollection(List.of(new ObjectId("000000000000000000000001"))) + .structAggregateEmbeddablesCollection(List.of(new StructAggregateEmbeddableIntegrationTests.Single(1))) + .build(); + sessionFactoryScope.inTransaction(session -> session.persist(item)); assertCollectionContainsExactly( """ @@ -185,32 +190,34 @@ void testArrayAndCollectionValues() { @Test void testArrayAndCollectionEmptyValues() { - var item = new ItemWithArrayAndCollectionValues( - 1, - new byte[0], - new char[0], - new int[0], - new long[0], - new double[0], - new boolean[0], - new Character[0], - new Integer[0], - new Long[0], - new Double[0], - new Boolean[0], - new String[0], - new BigDecimal[0], - new ObjectId[0], - new StructAggregateEmbeddableIntegrationTests.Single[0], - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - List.of()); + var item = ItemWithArrayAndCollectionValues.builder() + .id(1) + .bytes(new byte[0]) + .chars(new char[0]) + .ints(new int[0]) + .longs(new long[0]) + .doubles(new double[0]) + .booleans(new boolean[0]) + .boxedChars(new Character[0]) + .boxedInts(new Integer[0]) + .boxedLongs(new Long[0]) + .boxedDoubles(new Double[0]) + .boxedBooleans(new Boolean[0]) + .strings(new String[0]) + .bigDecimals(new BigDecimal[0]) + .objectIds(new ObjectId[0]) + .structAggregateEmbeddables(new StructAggregateEmbeddableIntegrationTests.Single[0]) + .charsCollection(List.of()) + .intsCollection(List.of()) + .longsCollection(List.of()) + .doublesCollection(List.of()) + .booleansCollection(List.of()) + .stringsCollection(List.of()) + .bigDecimalsCollection(List.of()) + .objectIdsCollection(List.of()) + .structAggregateEmbeddablesCollection(List.of()) + .build(); + sessionFactoryScope.inTransaction(session -> session.persist(item)); assertCollectionContainsExactly( """ @@ -291,34 +298,36 @@ void testArrayAndCollectionNullValues() { @Test void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections() { - var arraysAndCollections = new ArraysAndCollections( - new byte[] {2, 3}, - new char[] {'s', 't', 'r'}, - new int[] {5}, - new long[] {Long.MAX_VALUE, 6}, - new double[] {Double.MAX_VALUE}, - new boolean[] {true}, - new Character[] {'s', 't', 'r'}, - new Integer[] {7}, - new Long[] {8L}, - new Double[] {9.1d}, - new Boolean[] {true}, - new String[] {"str"}, - new BigDecimal[] {BigDecimal.valueOf(10.1)}, - new ObjectId[] {new ObjectId("000000000000000000000001")}, - new StructAggregateEmbeddableIntegrationTests.Single[] { + var arraysAndCollections = ArraysAndCollections.builder() + .bytes(new byte[] {2, 3}) + .chars(new char[] {'s', 't', 'r'}) + .ints(new int[] {5}) + .longs(new long[] {Long.MAX_VALUE, 6}) + .doubles(new double[] {Double.MAX_VALUE}) + .booleans(new boolean[] {true}) + .boxedChars(new Character[] {'s', 't', 'r'}) + .boxedInts(new Integer[] {7}) + .boxedLongs(new Long[] {8L}) + .boxedDoubles(new Double[] {9.1d}) + .boxedBooleans(new Boolean[] {true}) + .strings(new String[] {"str"}) + .bigDecimals(new BigDecimal[] {BigDecimal.valueOf(10.1)}) + .objectIds(new ObjectId[] {new ObjectId("000000000000000000000001")}) + .structAggregateEmbeddables(new StructAggregateEmbeddableIntegrationTests.Single[] { new StructAggregateEmbeddableIntegrationTests.Single(1) - }, - List.of('s', 't', 'r'), + }) + .charsCollection(List.of('s', 't', 'r')) // Hibernate ORM uses `LinkedHashSet`, forcing us to also use it, but messing up the order anyway - new LinkedHashSet<>(List.of(5)), - List.of(Long.MAX_VALUE, 6L), - List.of(Double.MAX_VALUE), - List.of(true), - List.of("str"), - List.of(BigDecimal.valueOf(10.1)), - List.of(new ObjectId("000000000000000000000001")), - List.of(new StructAggregateEmbeddableIntegrationTests.Single(1))); + .intsCollection(new LinkedHashSet<>(List.of(5))) + .longsCollection(List.of(Long.MAX_VALUE, 6L)) + .doublesCollection(List.of(Double.MAX_VALUE)) + .booleansCollection(List.of(true)) + .stringsCollection(List.of("str")) + .bigDecimalsCollection(List.of(BigDecimal.valueOf(10.1))) + .objectIdsCollection(List.of(new ObjectId("000000000000000000000001"))) + .structAggregateEmbeddablesCollection(List.of(new StructAggregateEmbeddableIntegrationTests.Single(1))) + .build(); + var item = new ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections( 1, new ArraysAndCollections[] {arraysAndCollections}, List.of()); sessionFactoryScope.inTransaction(session -> session.persist(item)); @@ -489,6 +498,9 @@ private static void assertCollectionContainsExactly(String documentAsJsonObject) @Entity @Table(name = "items") + @NoArgsConstructor + @AllArgsConstructor + @Builder static class ItemWithArrayAndCollectionValues { @Id int id; @@ -517,82 +529,18 @@ static class ItemWithArrayAndCollectionValues { Collection bigDecimalsCollection; Collection objectIdsCollection; Collection structAggregateEmbeddablesCollection; - - ItemWithArrayAndCollectionValues() {} - - ItemWithArrayAndCollectionValues( - int id, - byte[] bytes, - char[] chars, - int[] ints, - long[] longs, - double[] doubles, - boolean[] booleans, - Character[] boxedChars, - Integer[] boxedInts, - Long[] boxedLongs, - Double[] boxedDoubles, - Boolean[] boxedBooleans, - String[] strings, - BigDecimal[] bigDecimals, - ObjectId[] objectIds, - StructAggregateEmbeddableIntegrationTests.Single[] structAggregateEmbeddables, - Collection charsCollection, - Collection intsCollection, - Collection longsCollection, - Collection doublesCollection, - Collection booleansCollection, - Collection stringsCollection, - Collection bigDecimalsCollection, - Collection objectIdsCollection, - Collection structAggregateEmbeddablesCollection) { - this.id = id; - this.bytes = bytes; - this.chars = chars; - this.ints = ints; - this.longs = longs; - this.doubles = doubles; - this.booleans = booleans; - this.boxedChars = boxedChars; - this.boxedInts = boxedInts; - this.boxedLongs = boxedLongs; - this.boxedDoubles = boxedDoubles; - this.boxedBooleans = boxedBooleans; - this.strings = strings; - this.bigDecimals = bigDecimals; - this.objectIds = objectIds; - this.structAggregateEmbeddables = structAggregateEmbeddables; - this.charsCollection = charsCollection; - this.intsCollection = intsCollection; - this.longsCollection = longsCollection; - this.doublesCollection = doublesCollection; - this.booleansCollection = booleansCollection; - this.stringsCollection = stringsCollection; - this.bigDecimalsCollection = bigDecimalsCollection; - this.objectIdsCollection = objectIdsCollection; - this.structAggregateEmbeddablesCollection = structAggregateEmbeddablesCollection; - } } @Entity @Table(name = "items") + @NoArgsConstructor + @AllArgsConstructor static class ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections { @Id int id; ArraysAndCollections[] structAggregateEmbeddables; Collection structAggregateEmbeddablesCollection; - - ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections() {} - - ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections( - int id, - ArraysAndCollections[] structAggregateEmbeddables, - Collection structAggregateEmbeddablesCollection) { - this.id = id; - this.structAggregateEmbeddables = structAggregateEmbeddables; - this.structAggregateEmbeddablesCollection = structAggregateEmbeddablesCollection; - } } @Nested @@ -670,36 +618,25 @@ void testCollectionOfEmbeddablesElementCollectionValue() { @Entity @Table(name = "items") + @NoArgsConstructor + @AllArgsConstructor static class ItemWithBoxedBytesArrayValue { @Id int id; byte[] bytes; Byte[] boxedBytes; - - ItemWithBoxedBytesArrayValue() {} - - ItemWithBoxedBytesArrayValue(int id, byte[] bytes, Byte[] boxedBytes) { - this.id = id; - this.bytes = bytes; - this.boxedBytes = boxedBytes; - } } @Entity @Table(name = "items") + @NoArgsConstructor + @AllArgsConstructor static class ItemWithBytesCollectionValue { @Id int id; Collection bytes; - - ItemWithBytesCollectionValue() {} - - ItemWithBytesCollectionValue(int id, Collection bytes) { - this.id = id; - this.bytes = bytes; - } } /** diff --git a/src/integrationTest/java/com/mongodb/hibernate/embeddable/EmbeddableIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/embeddable/EmbeddableIntegrationTests.java index 58a725ad..1894c563 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/embeddable/EmbeddableIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/embeddable/EmbeddableIntegrationTests.java @@ -37,8 +37,12 @@ import java.math.BigDecimal; import java.util.Collection; import java.util.List; -import java.util.Objects; import java.util.Set; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import org.bson.BsonDocument; import org.bson.types.ObjectId; import org.hibernate.HibernateException; @@ -507,6 +511,8 @@ private static void assertCollectionContainsExactly(String documentAsJsonObject) @Entity @Table(name = "items") + @NoArgsConstructor + @AllArgsConstructor static class ItemWithFlattenedValues { @Id Single flattenedId; @@ -516,70 +522,34 @@ static class ItemWithFlattenedValues { @AttributeOverride(name = "a", column = @Column(name = "flattened2_a")) PairWithParent flattened2; - - ItemWithFlattenedValues() {} - - ItemWithFlattenedValues(Single flattenedId, Single flattened1, PairWithParent flattened2) { - this.flattenedId = flattenedId; - this.flattened1 = flattened1; - this.flattened2 = flattened2; - } } @Embeddable + @NoArgsConstructor + @AllArgsConstructor + @EqualsAndHashCode public static class Single { int a; - - Single() {} - - Single(int a) { - this.a = a; - } - - @Override - public boolean equals(Object o) { - if (o == null || getClass() != o.getClass()) { - return false; - } - Single single = (Single) o; - return a == single.a; - } - - @Override - public int hashCode() { - return Objects.hashCode(a); - } } @Embeddable + @NoArgsConstructor static class PairWithParent { int a; Plural flattened; + /** + * Hibernate ORM requires getter/setter for a {@link Parent} field, despite us using + * {@linkplain AccessType#FIELD field-based access}. + */ + @Getter + @Setter @Parent ItemWithFlattenedValues parent; - PairWithParent() {} - PairWithParent(int a, Plural flattened) { this.a = a; this.flattened = flattened; } - - /** - * Hibernate ORM requires a getter for a {@link Parent} field, despite us using {@linkplain AccessType#FIELD - * field-based access}. - */ - void setParent(ItemWithFlattenedValues parent) { - this.parent = parent; - } - - /** - * Hibernate ORM requires a getter for a {@link Parent} field, despite us using {@linkplain AccessType#FIELD - * field-based access}. - */ - ItemWithFlattenedValues getParent() { - return parent; - } } @Embeddable @@ -600,21 +570,18 @@ record Plural( @Entity @Table(name = "items") + @NoArgsConstructor + @AllArgsConstructor static class ItemWithFlattenedValueHavingArraysAndCollections { @Id int id; ArraysAndCollections flattened; - - ItemWithFlattenedValueHavingArraysAndCollections() {} - - ItemWithFlattenedValueHavingArraysAndCollections(int id, ArraysAndCollections flattened) { - this.id = id; - this.flattened = flattened; - } } @Embeddable + @NoArgsConstructor + @AllArgsConstructor static class ArraysAndCollections { byte[] bytes; char[] chars; @@ -640,59 +607,6 @@ static class ArraysAndCollections { Collection bigDecimalsCollection; Collection objectIdsCollection; Collection structAggregateEmbeddablesCollection; - - ArraysAndCollections() {} - - ArraysAndCollections( - byte[] bytes, - char[] chars, - int[] ints, - long[] longs, - double[] doubles, - boolean[] booleans, - Character[] boxedChars, - Integer[] boxedInts, - Long[] boxedLongs, - Double[] boxedDoubles, - Boolean[] boxedBooleans, - String[] strings, - BigDecimal[] bigDecimals, - ObjectId[] objectIds, - StructAggregateEmbeddableIntegrationTests.Single[] structAggregateEmbeddables, - List charsCollection, - Set intsCollection, - Collection longsCollection, - Collection doublesCollection, - Collection booleansCollection, - Collection stringsCollection, - Collection bigDecimalsCollection, - Collection objectIdsCollection, - Collection structAggregateEmbeddablesCollection) { - this.bytes = bytes; - this.chars = chars; - this.ints = ints; - this.longs = longs; - this.doubles = doubles; - this.booleans = booleans; - this.boxedChars = boxedChars; - this.boxedInts = boxedInts; - this.boxedLongs = boxedLongs; - this.boxedDoubles = boxedDoubles; - this.boxedBooleans = boxedBooleans; - this.strings = strings; - this.bigDecimals = bigDecimals; - this.objectIds = objectIds; - this.structAggregateEmbeddables = structAggregateEmbeddables; - this.charsCollection = charsCollection; - this.intsCollection = intsCollection; - this.longsCollection = longsCollection; - this.doublesCollection = doublesCollection; - this.booleansCollection = booleansCollection; - this.stringsCollection = stringsCollection; - this.bigDecimalsCollection = bigDecimalsCollection; - this.objectIdsCollection = objectIdsCollection; - this.structAggregateEmbeddablesCollection = structAggregateEmbeddablesCollection; - } } @Nested @@ -734,17 +648,12 @@ static class ItemWithPluralAsId { @Entity @Table(name = "items") + @AllArgsConstructor static class ItemWithFlattenedValueHavingStructAggregateEmbeddable { @Id int id; SingleHavingStructAggregateEmbeddable flattened; - - ItemWithFlattenedValueHavingStructAggregateEmbeddable( - int id, SingleHavingStructAggregateEmbeddable flattened) { - this.id = id; - this.flattened = flattened; - } } @Embeddable diff --git a/src/integrationTest/java/com/mongodb/hibernate/embeddable/StructAggregateEmbeddableIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/embeddable/StructAggregateEmbeddableIntegrationTests.java index e42bb6d3..29d33fd8 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/embeddable/StructAggregateEmbeddableIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/embeddable/StructAggregateEmbeddableIntegrationTests.java @@ -38,6 +38,9 @@ import java.util.Collection; import java.util.List; import java.util.Set; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; import org.bson.BsonDocument; import org.bson.types.ObjectId; import org.hibernate.annotations.Parent; @@ -241,31 +244,32 @@ void testNestedValueHavingArraysAndCollections() { var item = new ItemWithNestedValueHavingArraysAndCollections( 1, // TODO-HIBERNATE-48 sprinkle on `null` array/collection elements - new ArraysAndCollections( - new byte[] {2, 3}, - new char[] {'s', 't', 'r'}, - new int[] {5}, - new long[] {Long.MAX_VALUE, 6}, - new double[] {Double.MAX_VALUE}, - new boolean[] {true}, - new Character[] {'s', 't', 'r'}, - new Integer[] {7}, - new Long[] {8L}, - new Double[] {9.1d}, - new Boolean[] {true}, - new String[] {"str"}, - new BigDecimal[] {BigDecimal.valueOf(10.1)}, - new ObjectId[] {new ObjectId("000000000000000000000001")}, - new Single[] {new Single(1)}, - List.of('s', 't', 'r'), - Set.of(5), - List.of(Long.MAX_VALUE, 6L), - List.of(Double.MAX_VALUE), - List.of(true), - List.of("str"), - List.of(BigDecimal.valueOf(10.1)), - List.of(new ObjectId("000000000000000000000001")), - List.of(new Single(1)))); + ArraysAndCollections.builder() + .bytes(new byte[] {2, 3}) + .chars(new char[] {'s', 't', 'r'}) + .ints(new int[] {5}) + .longs(new long[] {Long.MAX_VALUE, 6}) + .doubles(new double[] {Double.MAX_VALUE}) + .booleans(new boolean[] {true}) + .boxedChars(new Character[] {'s', 't', 'r'}) + .boxedInts(new Integer[] {7}) + .boxedLongs(new Long[] {8L}) + .boxedDoubles(new Double[] {9.1d}) + .boxedBooleans(new Boolean[] {true}) + .strings(new String[] {"str"}) + .bigDecimals(new BigDecimal[] {BigDecimal.valueOf(10.1)}) + .objectIds(new ObjectId[] {new ObjectId("000000000000000000000001")}) + .structAggregateEmbeddables(new Single[] {new Single(1)}) + .charsCollection(List.of('s', 't', 'r')) + .intsCollection(Set.of(5)) + .longsCollection(List.of(Long.MAX_VALUE, 6L)) + .doublesCollection(List.of(Double.MAX_VALUE)) + .booleansCollection(List.of(true)) + .stringsCollection(List.of("str")) + .bigDecimalsCollection(List.of(BigDecimal.valueOf(10.1))) + .objectIdsCollection(List.of(new ObjectId("000000000000000000000001"))) + .structAggregateEmbeddablesCollection(List.of(new Single(1))) + .build()); sessionFactoryScope.inTransaction(session -> session.persist(item)); assertCollectionContainsExactly( """ @@ -352,31 +356,32 @@ void testNestedValueHavingArraysAndCollections() { void testNestedValueHavingEmptyArraysAndCollections() { var item = new ItemWithNestedValueHavingArraysAndCollections( 1, - new ArraysAndCollections( - new byte[0], - new char[0], - new int[0], - new long[0], - new double[0], - new boolean[0], - new Character[0], - new Integer[0], - new Long[0], - new Double[0], - new Boolean[0], - new String[0], - new BigDecimal[0], - new ObjectId[0], - new Single[0], - List.of(), - Set.of(), - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - List.of(), - List.of())); + ArraysAndCollections.builder() + .bytes(new byte[0]) + .chars(new char[0]) + .ints(new int[0]) + .longs(new long[0]) + .doubles(new double[0]) + .booleans(new boolean[0]) + .boxedChars(new Character[0]) + .boxedInts(new Integer[0]) + .boxedLongs(new Long[0]) + .boxedDoubles(new Double[0]) + .boxedBooleans(new Boolean[0]) + .strings(new String[0]) + .bigDecimals(new BigDecimal[0]) + .objectIds(new ObjectId[0]) + .structAggregateEmbeddables(new Single[0]) + .charsCollection(List.of()) + .intsCollection(Set.of()) + .longsCollection(List.of()) + .doublesCollection(List.of()) + .booleansCollection(List.of()) + .stringsCollection(List.of()) + .bigDecimalsCollection(List.of()) + .objectIdsCollection(List.of()) + .structAggregateEmbeddablesCollection(List.of()) + .build()); sessionFactoryScope.inTransaction(session -> session.persist(item)); assertCollectionContainsExactly( """ @@ -527,6 +532,8 @@ private static void assertCollectionContainsExactly(String documentAsJsonObject) @Entity @Table(name = "items") + @NoArgsConstructor + @AllArgsConstructor static class ItemWithNestedValues { @Id EmbeddableIntegrationTests.Single flattenedId; @@ -534,38 +541,25 @@ static class ItemWithNestedValues { Single nested1; PairWithParent nested2; - - ItemWithNestedValues() {} - - ItemWithNestedValues(EmbeddableIntegrationTests.Single flattenedId, Single nested1, PairWithParent nested2) { - this.flattenedId = flattenedId; - this.nested1 = nested1; - this.nested2 = nested2; - } } @Embeddable @Struct(name = "Single") + @NoArgsConstructor + @AllArgsConstructor public static class Single { public int a; - - Single() {} - - public Single(int a) { - this.a = a; - } } @Embeddable @Struct(name = "PairWithParent") + @NoArgsConstructor static class PairWithParent { int a; Plural nested; @Parent ItemWithNestedValues parent; - PairWithParent() {} - PairWithParent(int a, Plural nested) { this.a = a; this.nested = nested; @@ -607,22 +601,20 @@ record Plural( @Entity @Table(name = "items") + @NoArgsConstructor + @AllArgsConstructor static class ItemWithNestedValueHavingArraysAndCollections { @Id int id; ArraysAndCollections nested; - - ItemWithNestedValueHavingArraysAndCollections() {} - - ItemWithNestedValueHavingArraysAndCollections(int id, ArraysAndCollections nested) { - this.id = id; - this.nested = nested; - } } @Embeddable @Struct(name = "ArraysAndCollections") + @NoArgsConstructor + @AllArgsConstructor + @Builder public static class ArraysAndCollections { byte[] bytes; char[] chars; @@ -648,59 +640,6 @@ public static class ArraysAndCollections { Collection bigDecimalsCollection; Collection objectIdsCollection; Collection structAggregateEmbeddablesCollection; - - ArraysAndCollections() {} - - public ArraysAndCollections( - byte[] bytes, - char[] chars, - int[] ints, - long[] longs, - double[] doubles, - boolean[] booleans, - Character[] boxedChars, - Integer[] boxedInts, - Long[] boxedLongs, - Double[] boxedDoubles, - Boolean[] boxedBooleans, - String[] strings, - BigDecimal[] bigDecimals, - ObjectId[] objectIds, - Single[] structAggregateEmbeddables, - List charsCollection, - Set intsCollection, - Collection longsCollection, - Collection doublesCollection, - Collection booleansCollection, - Collection stringsCollection, - Collection bigDecimalsCollection, - Collection objectIdsCollection, - Collection structAggregateEmbeddablesCollection) { - this.bytes = bytes; - this.chars = chars; - this.ints = ints; - this.longs = longs; - this.doubles = doubles; - this.booleans = booleans; - this.boxedChars = boxedChars; - this.boxedInts = boxedInts; - this.boxedLongs = boxedLongs; - this.boxedDoubles = boxedDoubles; - this.boxedBooleans = boxedBooleans; - this.strings = strings; - this.bigDecimals = bigDecimals; - this.objectIds = objectIds; - this.structAggregateEmbeddables = structAggregateEmbeddables; - this.charsCollection = charsCollection; - this.intsCollection = intsCollection; - this.longsCollection = longsCollection; - this.doublesCollection = doublesCollection; - this.booleansCollection = booleansCollection; - this.stringsCollection = stringsCollection; - this.bigDecimalsCollection = bigDecimalsCollection; - this.objectIdsCollection = objectIdsCollection; - this.structAggregateEmbeddablesCollection = structAggregateEmbeddablesCollection; - } } @Nested @@ -793,18 +732,13 @@ record ItemWithNestedValueHavingNonUpdatable(@Id int id, PairHavingNonUpdatable @Embeddable @Struct(name = "PairHavingNonUpdatable") + @NoArgsConstructor + @AllArgsConstructor static class PairHavingNonUpdatable { @Column(updatable = false) int a; int b; - - PairHavingNonUpdatable() {} - - PairHavingNonUpdatable(int a, int b) { - this.a = a; - this.b = b; - } } @Entity @@ -822,18 +756,13 @@ record PairAllNonInsertable(@Column(insertable = false) int a, @Column(insertabl @Entity @Table(name = "items") + @NoArgsConstructor + @AllArgsConstructor static class ItemWithPolymorphicPersistentAttribute { @Id int id; Polymorphic polymorphic; - - ItemWithPolymorphicPersistentAttribute() {} - - ItemWithPolymorphicPersistentAttribute(int id, Polymorphic polymorphic) { - this.id = id; - this.polymorphic = polymorphic; - } } @Embeddable @@ -844,28 +773,20 @@ abstract static class Polymorphic { @Embeddable @Struct(name = "Concrete") + @NoArgsConstructor + @AllArgsConstructor static class Concrete extends Polymorphic { int a; - - Concrete() {} - - Concrete(int a) { - this.a = a; - } } @Entity @Table(name = "items") + @AllArgsConstructor static class ItemWithNestedValueHavingEmbeddable { @Id int id; SingleHavingEmbeddable nested; - - ItemWithNestedValueHavingEmbeddable(int id, SingleHavingEmbeddable nested) { - this.id = id; - this.nested = nested; - } } @Embeddable