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..156af066da3d34 --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Content.java @@ -0,0 +1,17 @@ +package org.acme.entities; + +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..5e44f24cecaca2 --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/EntityBase.java @@ -0,0 +1,15 @@ +package org.acme.entities; + +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..2143c20f0c7033 --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Folder.java @@ -0,0 +1,11 @@ +package org.acme.entities; + +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/FolderEndPoint.java b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/FolderEndPoint.java new file mode 100755 index 00000000000000..da713a669e459a --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/FolderEndPoint.java @@ -0,0 +1,26 @@ +package org.acme; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor; +import org.hibernate.engine.spi.PersistentAttributeInterceptable; + +import org.acme.entities.Content; +import org.acme.entities.Folder; + +@Path("/folder") +public class FolderEndPoint { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + Folder f = Folder.findById(1L); + Content content = f.content; + final PersistentAttributeInterceptable interceptable = (PersistentAttributeInterceptable) content; + final EnhancementAsProxyLazinessInterceptor interceptor = (EnhancementAsProxyLazinessInterceptor) interceptable.$$_hibernate_getInterceptor(); + return "name: " + content.name; + } +} \ No newline at end of file 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..7da1bb0994efe9 --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/Video.java @@ -0,0 +1,10 @@ +package org.acme.entities; + +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..0c44b2dd7595e2 --- /dev/null +++ b/integration-tests/hibernate-orm-panache/src/test/java/io/quarkus/it/panache/HibernateProxyFieldAccessTest.java @@ -0,0 +1,21 @@ +package io.quarkus.it.panache; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; + +@QuarkusTest +public class HibernateProxyFieldAccessTest { + + @Test + public void testHelloEndpoint() { + given() + .when().get("/folder") + .then() + .statusCode(200) + .body(is("name: it is working!")); + } +}