diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/IllegalArgumentExceptionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/IllegalArgumentExceptionTest.java index 7ab1c6bc26..ab04b005b9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/IllegalArgumentExceptionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/IllegalArgumentExceptionTest.java @@ -219,8 +219,21 @@ public class IllegalArgumentExceptionTest { } @Test - public void testQueryWrongReturnType(EntityManagerFactoryScope scope) { + public void testNonExistingNativeQuery(EntityManagerFactoryScope scope) { scope.inEntityManager( + entityManager -> + Assertions.assertThrows( + IllegalArgumentException.class, + () -> { + entityManager.createNamedQuery( "NonExisting_NativeQuery" ); + } + ) + ); + } + + @Test + public void testQueryWrongReturnType(EntityManagerFactoryScope scope) { + scope.inTransaction( entityManager -> { Assertions.assertThrows( IllegalArgumentException.class, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/JtaIllegalArgumentExceptionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/JtaIllegalArgumentExceptionTest.java new file mode 100644 index 0000000000..2a3a00e36f --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/JtaIllegalArgumentExceptionTest.java @@ -0,0 +1,67 @@ +package org.hibernate.orm.test.jpa.compliance; + +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.orm.test.jpa.transaction.JtaPlatformSettingProvider; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; +import org.hibernate.testing.orm.junit.SettingProvider; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; + +@Jpa( + annotatedClasses = { JtaIllegalArgumentExceptionTest.Person.class }, + integrationSettings = { + @Setting(name = org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, value = "org.hibernate.testing.jta.JtaAwareConnectionProviderImpl"), + @Setting(name = org.hibernate.cfg.AvailableSettings.JPA_TRANSACTION_TYPE, value = "JTA") + }, + settingProviders = { + @SettingProvider( + settingName = AvailableSettings.JTA_PLATFORM, + provider = JtaPlatformSettingProvider.class + ) + } +) +@TestForIssue( jiraKey = "HHH-15225") +public class JtaIllegalArgumentExceptionTest { + + @Test + public void testNonExistingNativeQuery(EntityManagerFactoryScope scope) { + scope.inEntityManager( + entityManager -> + Assertions.assertThrows( + IllegalArgumentException.class, + () -> { + entityManager.createNamedQuery( "NonExisting_NativeQuery" ); + } + ) + ); + } + + @Test + public void testNonExistingNativeQuery2(EntityManagerFactoryScope scope) { + scope.inEntityManager( + entityManager -> + Assertions.assertThrows( + IllegalArgumentException.class, + () -> { + entityManager.createNamedQuery( "NonExisting_NativeQuery", Person.class ); + } + ) + ); + } + + @Entity(name = "Person") + public static class Person { + + @Id + private Integer id; + + private String name; + } +}