From aa068be375692f00986c774e1e0def9779646561 Mon Sep 17 00:00:00 2001 From: radovanradic Date: Wed, 15 Jan 2025 10:44:14 +0100 Subject: [PATCH 1/2] Added test for issue "Null value read for non-null constructor argument" fixed in core --- doc-examples/jdbc-example-java/build.gradle | 2 ++ .../src/main/java/example/Item.java | 21 ++++++++++++++ .../src/main/java/example/ItemRepository.java | 14 +++++++++ .../test/java/example/ItemRepositorySpec.java | 29 +++++++++++++++++++ gradle/libs.versions.toml | 8 +++++ 5 files changed, 74 insertions(+) create mode 100644 doc-examples/jdbc-example-java/src/main/java/example/Item.java create mode 100644 doc-examples/jdbc-example-java/src/main/java/example/ItemRepository.java create mode 100644 doc-examples/jdbc-example-java/src/test/java/example/ItemRepositorySpec.java diff --git a/doc-examples/jdbc-example-java/build.gradle b/doc-examples/jdbc-example-java/build.gradle index add19fd2b6..797fb18b30 100644 --- a/doc-examples/jdbc-example-java/build.gradle +++ b/doc-examples/jdbc-example-java/build.gradle @@ -13,9 +13,11 @@ micronaut { } dependencies { + annotationProcessor libs.lombok annotationProcessor projects.micronautDataProcessor annotationProcessor mnSql.hibernate.jpamodelgen annotationProcessor mnValidation.micronaut.validation + compileOnly libs.lombok implementation projects.micronautDataJdbc implementation mnRxjava2.micronaut.rxjava2 implementation mn.micronaut.http.client diff --git a/doc-examples/jdbc-example-java/src/main/java/example/Item.java b/doc-examples/jdbc-example-java/src/main/java/example/Item.java new file mode 100644 index 0000000000..ad4d855519 --- /dev/null +++ b/doc-examples/jdbc-example-java/src/main/java/example/Item.java @@ -0,0 +1,21 @@ +package example; + +import io.micronaut.core.annotation.Introspected; +import io.micronaut.data.annotation.Id; +import io.micronaut.data.annotation.MappedEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@MappedEntity +@Introspected +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Item { + @Id + private Integer id; + private String title; +} diff --git a/doc-examples/jdbc-example-java/src/main/java/example/ItemRepository.java b/doc-examples/jdbc-example-java/src/main/java/example/ItemRepository.java new file mode 100644 index 0000000000..0ccd2c35fe --- /dev/null +++ b/doc-examples/jdbc-example-java/src/main/java/example/ItemRepository.java @@ -0,0 +1,14 @@ +package example; + +import io.micronaut.data.annotation.Query; +import io.micronaut.data.jdbc.annotation.JdbcRepository; +import io.micronaut.data.model.query.builder.sql.Dialect; +import io.micronaut.data.repository.GenericRepository; + +import java.util.List; + +@JdbcRepository(dialect = Dialect.H2) +public interface ItemRepository extends GenericRepository { + @Query("SELECT 1 AS id, NULL AS title") + List getItems(); +} diff --git a/doc-examples/jdbc-example-java/src/test/java/example/ItemRepositorySpec.java b/doc-examples/jdbc-example-java/src/test/java/example/ItemRepositorySpec.java new file mode 100644 index 0000000000..285fb3d62a --- /dev/null +++ b/doc-examples/jdbc-example-java/src/test/java/example/ItemRepositorySpec.java @@ -0,0 +1,29 @@ +package example; + +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +@MicronautTest(transactional = false) +class ItemRepositorySpec { + + @Inject + private ItemRepository itemRepository; + + /** + * Verifies issue https://github.com/micronaut-projects/micronaut-data/issues/3267 is fixed in core. + */ + @Test + void testGetItems() { + List items = itemRepository.getItems(); + assertEquals(1, items.size()); + Item item = items.get(0); + assertEquals(1, item.getId()); + assertNull(item.getTitle()); + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5787cafe50..4c1d568b5f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,6 +27,10 @@ managed-javax-persistence = "2.2" spring-data = "3.4.1" +# Lombok + +lombok = "1.18.36" + # Testing and benchmarking benchmark-spring-data = "2024.1.1" @@ -89,6 +93,10 @@ managed-javax-persistence-api = { module = "javax.persistence:javax.persistence- spring-data-jpa = { module = "org.springframework.data:spring-data-jpa", version.ref = "spring-data" } spring-data-commons = { module = "org.springframework.data:spring-data-commons", version.ref = "spring-data" } +# Lombok + +lombok = { module = "org.projectlombok:lombok", version.ref = "lombok" } + # AZURE COSMOS micronaut-azure-cosmos = { module = "io.micronaut.azure:micronaut-azure-cosmos", version.ref = "micronaut-azure" } From b4155d1b0f1a83cff4ffd1614af5f34c66c43f34 Mon Sep 17 00:00:00 2001 From: radovanradic Date: Thu, 16 Jan 2025 08:47:32 +0100 Subject: [PATCH 2/2] Use latest micronaut-core 4.7.12 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4c1d568b5f..6dfb9bf711 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -micronaut = "4.7.11" +micronaut = "4.7.12" micronaut-platform = "4.7.4" micronaut-docs = "2.0.0" micronaut-gradle-plugin = "4.4.4"