diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/pom.xml b/extensions/panache/hibernate-orm-panache-kotlin/deployment/pom.xml
index 07654f326f616..67133b7cac96d 100644
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/pom.xml
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/pom.xml
@@ -86,6 +86,41 @@
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+
+
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheResourceProcessor.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheResourceProcessor.java
index 0a4c4a09ed064..de7289f94bbce 100644
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheResourceProcessor.java
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheResourceProcessor.java
@@ -16,14 +16,18 @@
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
+import javax.persistence.Id;
import javax.persistence.Transient;
+import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Type;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
+import io.quarkus.arc.deployment.ValidationPhaseBuildItem;
import io.quarkus.arc.processor.BeanInfo;
+import io.quarkus.builder.BuildException;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
@@ -34,6 +38,7 @@
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.util.JandexUtil;
import io.quarkus.hibernate.orm.deployment.AdditionalJpaModelBuildItem;
import io.quarkus.hibernate.orm.deployment.HibernateEnhancersRegisteredBuildItem;
import io.quarkus.hibernate.orm.deployment.JpaModelPersistenceUnitMappingBuildItem;
@@ -47,7 +52,8 @@
import io.quarkus.panache.common.deployment.TypeBundle;
public final class KotlinPanacheResourceProcessor {
-
+ private static final DotName DOTNAME_ID = DotName.createSimple(Id.class.getName());
+ private static final DotName DOTNAME_PANACHE_ENTITY = DotName.createSimple(PanacheEntity.class.getName());
private static final Set UNREMOVABLE_BEANS = singleton(createSimple(EntityManager.class.getName()));
static final DotName TRANSIENT = DotName.createSimple(Transient.class.getName());
@@ -206,4 +212,21 @@ List produceModel() {
// only transforms classes from the application jar, so we do our own transforming
return Collections.singletonList(new AdditionalJpaModelBuildItem(PanacheEntity.class));
}
+
+ @BuildStep
+ ValidationPhaseBuildItem.ValidationErrorBuildItem validate(ValidationPhaseBuildItem validationPhase,
+ CombinedIndexBuildItem index) throws BuildException {
+ // we verify that no ID fields are defined (via @Id) when extending PanacheEntity
+ for (AnnotationInstance annotationInstance : index.getIndex().getAnnotations(DOTNAME_ID)) {
+ ClassInfo info = JandexUtil.getEnclosingClass(annotationInstance);
+ if (JandexUtil.isSubclassOf(index.getIndex(), info, DOTNAME_PANACHE_ENTITY)) {
+ BuildException be = new BuildException("You provide a JPA identifier via @Id inside '" + info.name() +
+ "' but one is already provided by PanacheEntity, " +
+ "your class should extend PanacheEntityBase instead, or use the id provided by PanacheEntity",
+ Collections.emptyList());
+ return new ValidationPhaseBuildItem.ValidationErrorBuildItem(be);
+ }
+ }
+ return null;
+ }
}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DefaultPanacheEntityToStringTest.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DefaultPanacheEntityToStringTest.java
deleted file mode 100644
index 20cda2c91c4da..0000000000000
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DefaultPanacheEntityToStringTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package io.quarkus.hibernate.orm.panache.kotlin.deployment.test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import org.junit.jupiter.api.Test;
-
-import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity;
-
-public class DefaultPanacheEntityToStringTest {
-
- @Test
- public void testDefaultToStringMethod() {
- MyPanacheEntity myPanacheEntityWithId = new MyPanacheEntity(2912l);
- assertEquals("MyPanacheEntity<2912>", myPanacheEntityWithId.toString());
-
- MyPanacheEntity myPanacheEntityWithNullId = new MyPanacheEntity(null);
- assertEquals("MyPanacheEntity", myPanacheEntityWithNullId.toString());
- }
-
- static class MyPanacheEntity extends PanacheEntity {
- public MyPanacheEntity(Long id) {
- this.setId(id);
- }
- }
-}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/NoConfigTest.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/NoConfigTest.java
deleted file mode 100644
index b0d88c9d4a057..0000000000000
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/NoConfigTest.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package io.quarkus.hibernate.orm.panache.kotlin.deployment.test;
-
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-
-import io.quarkus.test.QuarkusUnitTest;
-
-public class NoConfigTest {
-
- @RegisterExtension
- static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer(
- () -> ShrinkWrap.create(JavaArchive.class));
-
- @Test
- public void testNoConfig() {
- // we should be able to start the application, even with no configuration at all
- }
-}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitConfigTest.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitConfigTest.java
deleted file mode 100644
index 27e4631e9ce6c..0000000000000
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitConfigTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu;
-
-import org.hamcrest.Matchers;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity;
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity;
-import io.quarkus.test.QuarkusUnitTest;
-import io.restassured.RestAssured;
-
-public class DefaultPersistenceUnitConfigTest {
-
- @RegisterExtension
- static QuarkusUnitTest runner = new QuarkusUnitTest()
- .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
- .addClasses(FirstEntity.class, SecondEntity.class, PanacheTestResource.class)
- .addAsResource("application.properties"));
-
- @Test
- public void panacheOperations() {
- /**
- * First entity operations
- */
- RestAssured.when().get("/persistence-unit/first/name-1").then().body(Matchers.is("name-1"));
- RestAssured.when().get("/persistence-unit/first/name-2").then().body(Matchers.is("name-2"));
-
- /**
- * second entity operations
- */
- RestAssured.when().get("/persistence-unit/second/name-1").then().body(Matchers.is("name-1"));
- RestAssured.when().get("/persistence-unit/second/name-2").then().body(Matchers.is("name-2"));
- }
-}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitFileTest.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitFileTest.java
deleted file mode 100644
index 644544bc29783..0000000000000
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitFileTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu;
-
-import org.hamcrest.Matchers;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.StringAsset;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity;
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity;
-import io.quarkus.test.QuarkusUnitTest;
-import io.restassured.RestAssured;
-
-public class DefaultPersistenceUnitFileTest {
-
- @RegisterExtension
- static QuarkusUnitTest runner = new QuarkusUnitTest()
- .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
- .addClasses(FirstEntity.class, SecondEntity.class, PanacheTestResource.class)
- .addAsManifestResource("META-INF/some-persistence.xml", "persistence.xml")
- .addAsResource(new StringAsset(
- "quarkus.datasource.db-kind=h2\n" +
- "quarkus.datasource.jdbc.url=jdbc:h2:mem:default;DB_CLOSE_DELAY=-1"),
- "application.properties"));
-
- @Test
- public void panacheOperations() {
- /**
- * First entity operations
- */
- RestAssured.when().get("/persistence-unit/first/name-1").then().body(Matchers.is("name-1"));
- RestAssured.when().get("/persistence-unit/first/name-2").then().body(Matchers.is("name-2"));
-
- /**
- * second entity operations
- */
- RestAssured.when().get("/persistence-unit/second/name-1").then().body(Matchers.is("name-1"));
- RestAssured.when().get("/persistence-unit/second/name-2").then().body(Matchers.is("name-2"));
- }
-}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/ErroneousPersistenceUnitConfigTest.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/ErroneousPersistenceUnitConfigTest.java
deleted file mode 100644
index b627ce9e1ab85..0000000000000
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/ErroneousPersistenceUnitConfigTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu;
-
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity;
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity;
-import io.quarkus.test.QuarkusUnitTest;
-
-public class ErroneousPersistenceUnitConfigTest {
-
- @RegisterExtension
- static QuarkusUnitTest runner = new QuarkusUnitTest()
- .setExpectedException(IllegalStateException.class)
- .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
- .addClasses(FirstEntity.class, SecondEntity.class, PanacheTestResource.class)
- .addAsResource("application-erroneous-multiple-persistence-units.properties", "application.properties"));
-
- @Test
- public void shouldNotReachHere() {
- Assertions.fail();
- }
-}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/MultiplePersistenceUnitConfigTest.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/MultiplePersistenceUnitConfigTest.java
deleted file mode 100644
index fe0112835e775..0000000000000
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/MultiplePersistenceUnitConfigTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu;
-
-import org.hamcrest.Matchers;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity;
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity;
-import io.quarkus.test.QuarkusUnitTest;
-import io.restassured.RestAssured;
-
-public class MultiplePersistenceUnitConfigTest {
-
- @RegisterExtension
- static QuarkusUnitTest runner = new QuarkusUnitTest()
- .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
- .addClasses(FirstEntity.class, SecondEntity.class, PanacheTestResource.class)
- .addAsResource("application-multiple-persistence-units.properties", "application.properties"));
-
- @Test
- public void panacheOperations() {
- /**
- * First entity operations
- */
- RestAssured.when().get("/persistence-unit/first/name-1").then().body(Matchers.is("name-1"));
- RestAssured.when().get("/persistence-unit/first/name-2").then().body(Matchers.is("name-2"));
-
- /**
- * second entity operations
- */
- RestAssured.when().get("/persistence-unit/second/name-1").then().body(Matchers.is("name-1"));
- RestAssured.when().get("/persistence-unit/second/name-2").then().body(Matchers.is("name-2"));
- }
-}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/PanacheTestResource.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/PanacheTestResource.java
deleted file mode 100644
index ece78ca2826f6..0000000000000
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/PanacheTestResource.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu;
-
-import javax.transaction.Transactional;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity;
-import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity;
-
-@Path("/persistence-unit")
-public class PanacheTestResource {
-
- @GET
- @Path("/first/{name}")
- @Produces(MediaType.TEXT_PLAIN)
- @Transactional
- public String createWithFirstPuAndReturnCount(@PathParam("name") String name) {
- FirstEntity entity = new FirstEntity();
- entity.name = name;
- entity.persistAndFlush();
- return name;
- }
-
- @GET
- @Path("/second/{name}")
- @Produces(MediaType.TEXT_PLAIN)
- @Transactional
- public String createWithSecondPUAndReturnCount(@PathParam("name") String name) {
- SecondEntity entity = new SecondEntity();
- entity.name = name;
- entity.persistAndFlush();
- return name;
- }
-}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/first/FirstEntity.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/first/FirstEntity.java
deleted file mode 100644
index 013e6a87e2f3e..0000000000000
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/first/FirstEntity.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first;
-
-import javax.persistence.Entity;
-
-import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity;
-
-@Entity
-public class FirstEntity extends PanacheEntity {
-
- public String name;
-}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/second/SecondEntity.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/second/SecondEntity.java
deleted file mode 100644
index ef664e9153ce3..0000000000000
--- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/second/SecondEntity.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second;
-
-import javax.persistence.Entity;
-
-import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity;
-
-@Entity
-public class SecondEntity extends PanacheEntity {
-
- public String name;
-}
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DefaultPanacheEntityToStringTest.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DefaultPanacheEntityToStringTest.kt
new file mode 100644
index 0000000000000..05f2a5a63abf8
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DefaultPanacheEntityToStringTest.kt
@@ -0,0 +1,21 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test
+
+import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Test
+
+class DefaultPanacheEntityToStringTest {
+ @Test
+ fun testDefaultToStringMethod() {
+ val myPanacheEntityWithId = MyPanacheEntity(2912L)
+ Assertions.assertEquals("MyPanacheEntity<2912>", myPanacheEntityWithId.toString())
+ val myPanacheEntityWithNullId = MyPanacheEntity(null)
+ Assertions.assertEquals("MyPanacheEntity", myPanacheEntityWithNullId.toString())
+ }
+
+ internal class MyPanacheEntity(id: Long?) : PanacheEntity() {
+ init {
+ this.id = id
+ }
+ }
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DuplicateIdEntity.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DuplicateIdEntity.kt
new file mode 100644
index 0000000000000..95de85ad86e6f
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DuplicateIdEntity.kt
@@ -0,0 +1,9 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test
+
+import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
+import javax.persistence.Id
+
+class DuplicateIdEntity : PanacheEntity() {
+ @Id
+ var customId: String? = null
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DuplicateIdEntityTest.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DuplicateIdEntityTest.kt
new file mode 100644
index 0000000000000..126c527efd55e
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/DuplicateIdEntityTest.kt
@@ -0,0 +1,27 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test
+
+import io.quarkus.builder.BuildException
+import io.quarkus.test.QuarkusUnitTest
+import org.jboss.shrinkwrap.api.spec.JavaArchive
+import org.jboss.shrinkwrap.api.ShrinkWrap
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.extension.RegisterExtension
+
+class DuplicateIdEntityTest {
+ @Test
+ fun shouldThrow() {
+ Assertions.fail("A BuildException should have been thrown due to duplicate entity ID")
+ }
+
+ companion object {
+ @RegisterExtension
+ @JvmField
+ var runner = QuarkusUnitTest()
+ .setExpectedException(BuildException::class.java)
+ .setArchiveProducer {
+ ShrinkWrap.create(JavaArchive::class.java)
+ .addClasses(DuplicateIdEntity::class.java)
+ }
+ }
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/NoConfigTest.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/NoConfigTest.kt
new file mode 100644
index 0000000000000..a0a7ee0180d10
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/NoConfigTest.kt
@@ -0,0 +1,20 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test
+
+import io.quarkus.test.QuarkusUnitTest
+import org.jboss.shrinkwrap.api.ShrinkWrap
+import org.jboss.shrinkwrap.api.spec.JavaArchive
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.extension.RegisterExtension
+
+class NoConfigTest {
+ @Test
+ fun testNoConfig() {
+ // we should be able to start the application, even with no configuration at all
+ }
+
+ companion object {
+ @RegisterExtension
+ @JvmField
+ val config = QuarkusUnitTest().setArchiveProducer { ShrinkWrap.create(JavaArchive::class.java) }
+ }
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitConfigTest.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitConfigTest.kt
new file mode 100644
index 0000000000000..ed1df30f9b7b2
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitConfigTest.kt
@@ -0,0 +1,38 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu
+
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity
+import io.quarkus.test.QuarkusUnitTest
+import io.restassured.RestAssured
+import org.hamcrest.Matchers
+import org.jboss.shrinkwrap.api.ShrinkWrap
+import org.jboss.shrinkwrap.api.spec.JavaArchive
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.extension.RegisterExtension
+
+class DefaultPersistenceUnitConfigTest {
+ @Test
+ fun panacheOperations() {
+ /**
+ * First entity operations
+ */
+ RestAssured.`when`()["/persistence-unit/first/name-1"].then().body(Matchers.`is`("name-1"))
+ RestAssured.`when`()["/persistence-unit/first/name-2"].then().body(Matchers.`is`("name-2"))
+ /**
+ * second entity operations
+ */
+ RestAssured.`when`()["/persistence-unit/second/name-1"].then().body(Matchers.`is`("name-1"))
+ RestAssured.`when`()["/persistence-unit/second/name-2"].then().body(Matchers.`is`("name-2"))
+ }
+
+ companion object {
+ @RegisterExtension
+ @JvmField
+ var runner = QuarkusUnitTest()
+ .setArchiveProducer {
+ ShrinkWrap.create(JavaArchive::class.java)
+ .addClasses(FirstEntity::class.java, SecondEntity::class.java, PanacheTestResource::class.java)
+ .addAsResource("application.properties")
+ }
+ }
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitFileTest.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitFileTest.kt
new file mode 100644
index 0000000000000..709925e92ec58
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/DefaultPersistenceUnitFileTest.kt
@@ -0,0 +1,45 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu
+
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity
+import io.quarkus.test.QuarkusUnitTest
+import io.restassured.RestAssured
+import org.hamcrest.Matchers
+import org.jboss.shrinkwrap.api.ShrinkWrap
+import org.jboss.shrinkwrap.api.asset.StringAsset
+import org.jboss.shrinkwrap.api.spec.JavaArchive
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.extension.RegisterExtension
+
+class DefaultPersistenceUnitFileTest {
+ @Test
+ fun panacheOperations() {
+ /**
+ * First entity operations
+ */
+ RestAssured.`when`()["/persistence-unit/first/name-1"].then().body(Matchers.`is`("name-1"))
+ RestAssured.`when`()["/persistence-unit/first/name-2"].then().body(Matchers.`is`("name-2"))
+ /**
+ * second entity operations
+ */
+ RestAssured.`when`()["/persistence-unit/second/name-1"].then().body(Matchers.`is`("name-1"))
+ RestAssured.`when`()["/persistence-unit/second/name-2"].then().body(Matchers.`is`("name-2"))
+ }
+
+ companion object {
+ @RegisterExtension
+ @JvmField
+ var runner = QuarkusUnitTest()
+ .setArchiveProducer {
+ ShrinkWrap.create(JavaArchive::class.java)
+ .addClasses(FirstEntity::class.java, SecondEntity::class.java, PanacheTestResource::class.java)
+ .addAsManifestResource("META-INF/some-persistence.xml", "persistence.xml")
+ .addAsResource(StringAsset(
+ """
+ quarkus.datasource.db-kind=h2
+ quarkus.datasource.jdbc.url=jdbc:h2:mem:default;DB_CLOSE_DELAY=-1
+ """.trimIndent()),
+ "application.properties")
+ }
+ }
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/ErroneousPersistenceUnitConfigTest.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/ErroneousPersistenceUnitConfigTest.kt
new file mode 100644
index 0000000000000..b6eafd19511db
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/ErroneousPersistenceUnitConfigTest.kt
@@ -0,0 +1,29 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu
+
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity
+import io.quarkus.test.QuarkusUnitTest
+import org.jboss.shrinkwrap.api.ShrinkWrap
+import org.jboss.shrinkwrap.api.spec.JavaArchive
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.extension.RegisterExtension
+
+class ErroneousPersistenceUnitConfigTest {
+ @Test
+ fun shouldNotReachHere() {
+ Assertions.fail()
+ }
+
+ companion object {
+ @RegisterExtension
+ @JvmField
+ var runner = QuarkusUnitTest()
+ .setExpectedException(IllegalStateException::class.java)
+ .setArchiveProducer {
+ ShrinkWrap.create(JavaArchive::class.java)
+ .addClasses(FirstEntity::class.java, SecondEntity::class.java, PanacheTestResource::class.java)
+ .addAsResource("application-erroneous-multiple-persistence-units.properties", "application.properties")
+ }
+ }
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/MultiplePersistenceUnitConfigTest.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/MultiplePersistenceUnitConfigTest.kt
new file mode 100644
index 0000000000000..de835e2076c3c
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/MultiplePersistenceUnitConfigTest.kt
@@ -0,0 +1,38 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu
+
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity
+import io.quarkus.test.QuarkusUnitTest
+import io.restassured.RestAssured
+import org.hamcrest.Matchers
+import org.jboss.shrinkwrap.api.ShrinkWrap
+import org.jboss.shrinkwrap.api.spec.JavaArchive
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.extension.RegisterExtension
+
+class MultiplePersistenceUnitConfigTest {
+ @Test
+ fun panacheOperations() {
+ /**
+ * First entity operations
+ */
+ RestAssured.`when`()["/persistence-unit/first/name-1"].then().body(Matchers.`is`("name-1"))
+ RestAssured.`when`()["/persistence-unit/first/name-2"].then().body(Matchers.`is`("name-2"))
+ /**
+ * second entity operations
+ */
+ RestAssured.`when`()["/persistence-unit/second/name-1"].then().body(Matchers.`is`("name-1"))
+ RestAssured.`when`()["/persistence-unit/second/name-2"].then().body(Matchers.`is`("name-2"))
+ }
+
+ companion object {
+ @RegisterExtension
+ @JvmField
+ var runner = QuarkusUnitTest()
+ .setArchiveProducer {
+ ShrinkWrap.create(JavaArchive::class.java)
+ .addClasses(FirstEntity::class.java, SecondEntity::class.java, PanacheTestResource::class.java)
+ .addAsResource("application-multiple-persistence-units.properties", "application.properties")
+ }
+ }
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/PanacheTestResource.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/PanacheTestResource.kt
new file mode 100644
index 0000000000000..8d871527c1481
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/PanacheTestResource.kt
@@ -0,0 +1,35 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu
+
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first.FirstEntity
+import io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second.SecondEntity
+import javax.transaction.Transactional
+import javax.ws.rs.GET
+import javax.ws.rs.Path
+import javax.ws.rs.PathParam
+import javax.ws.rs.Produces
+import javax.ws.rs.core.MediaType
+
+@Path("/persistence-unit")
+class PanacheTestResource {
+ @GET
+ @Path("/first/{name}")
+ @Produces(MediaType.TEXT_PLAIN)
+ @Transactional
+ fun createWithFirstPuAndReturnCount(@PathParam("name") name: String?): String? {
+ val entity = FirstEntity()
+ entity.name = name
+ entity.persistAndFlush()
+ return name
+ }
+
+ @GET
+ @Path("/second/{name}")
+ @Produces(MediaType.TEXT_PLAIN)
+ @Transactional
+ fun createWithSecondPUAndReturnCount(@PathParam("name") name: String?): String? {
+ val entity = SecondEntity()
+ entity.name = name
+ entity.persistAndFlush()
+ return name
+ }
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/first/FirstEntity.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/first/FirstEntity.kt
new file mode 100644
index 0000000000000..0f6d2488bf018
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/first/FirstEntity.kt
@@ -0,0 +1,9 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.first
+
+import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
+import javax.persistence.Entity
+
+@Entity
+class FirstEntity : PanacheEntity() {
+ var name: String? = null
+}
\ No newline at end of file
diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/second/SecondEntity.kt b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/second/SecondEntity.kt
new file mode 100644
index 0000000000000..94cbff744517e
--- /dev/null
+++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/test/kotlin/io/quarkus/hibernate/orm/panache/kotlin/deployment/test/multiple_pu/second/SecondEntity.kt
@@ -0,0 +1,9 @@
+package io.quarkus.hibernate.orm.panache.kotlin.deployment.test.multiple_pu.second
+
+import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
+import javax.persistence.Entity
+
+@Entity
+class SecondEntity : PanacheEntity() {
+ var name: String? = null
+}
\ No newline at end of file