From 681e0c50d0415f5fb33cc52026ee74e9727812b5 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 15 May 2020 10:17:18 +0100 Subject: [PATCH] Test for #8932 Hibernate Lazy load issue --- .../java/io/quarkus/it/panache/Content.java | 17 +++++++++++++++++ .../java/io/quarkus/it/panache/EntityBase.java | 15 +++++++++++++++ .../java/io/quarkus/it/panache/Folder.java | 11 +++++++++++ .../io/quarkus/it/panache/TestEndpoint.java | 1 - .../main/java/io/quarkus/it/panache/Video.java | 10 ++++++++++ .../src/main/resources/import.sql | 2 ++ .../panache/HibernateProxyFieldAccessTest.java | 18 ++++++++++++++++++ 7 files changed, 73 insertions(+), 1 deletion(-) create mode 100755 integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Content.java create mode 100755 integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/EntityBase.java create mode 100755 integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Folder.java create mode 100755 integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Video.java create mode 100755 integration-tests/hibernate-orm-panache/src/main/resources/import.sql create mode 100644 integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/HibernateProxyFieldAccessTest.java diff --git a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Content.java b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Content.java new file mode 100755 index 00000000000000..e7d8ca5b56705d --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Content.java @@ -0,0 +1,17 @@ +package io.quarkus.it.panache; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; + +@Entity(name = "content") +@Inheritance(strategy = InheritanceType.JOINED) +public class Content extends EntityBase { + @Column(nullable = false) + public String name; + + // public String getName() { + // return name; + // } +} diff --git a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/EntityBase.java b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/EntityBase.java new file mode 100755 index 00000000000000..5fa65b311c6195 --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/EntityBase.java @@ -0,0 +1,15 @@ +package io.quarkus.it.panache; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +import io.quarkus.hibernate.orm.panache.PanacheEntityBase; + +@MappedSuperclass +public abstract class EntityBase extends PanacheEntityBase { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + public Long id; +} diff --git a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Folder.java b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Folder.java new file mode 100755 index 00000000000000..03805fd2ea05d6 --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Folder.java @@ -0,0 +1,11 @@ +package io.quarkus.it.panache; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ManyToOne; + +@Entity(name = "folder") +public class Folder extends EntityBase { + @ManyToOne(fetch = FetchType.LAZY, optional = false) + public Content content; +} diff --git a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/TestEndpoint.java b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/TestEndpoint.java index 133733c30dc58d..9e60ecec328968 100644 --- a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/TestEndpoint.java +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/TestEndpoint.java @@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; diff --git a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Video.java b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Video.java new file mode 100755 index 00000000000000..afa2487707dd01 --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Video.java @@ -0,0 +1,10 @@ +package io.quarkus.it.panache; + +import javax.persistence.Column; +import javax.persistence.Entity; + +@Entity(name = "video") +public class Video extends Content { + @Column(nullable = false) + public long length; +} diff --git a/integration-tests/hibernate-orm-panache/src/main/resources/import.sql b/integration-tests/hibernate-orm-panache/src/main/resources/import.sql new file mode 100755 index 00000000000000..7bdc9b0ca9b33e --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/resources/import.sql @@ -0,0 +1,2 @@ +insert into content values (1, 'it is working!'); +insert into folder values (1, 1); diff --git a/integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/HibernateProxyFieldAccessTest.java b/integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/HibernateProxyFieldAccessTest.java new file mode 100644 index 00000000000000..7e274c0096f7ab --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/HibernateProxyFieldAccessTest.java @@ -0,0 +1,18 @@ +package io.quarkus.it.panache; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class HibernateProxyFieldAccessTest { + + @Test + public void folderContentNameTest() { + Folder f = Folder.findById(1L); + Content content = f.content; + String name = content.name; + Assertions.assertEquals("it is working!", name); + } +}