Skip to content

Commit e60cb27

Browse files
committed
HHH-19307 - Test for issue
Signed-off-by: Jan Schatteman <[email protected]>
1 parent b27bd92 commit e60cb27

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/boot/BootFailureTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@
1111
import java.util.HashMap;
1212
import java.util.List;
1313
import java.util.Map;
14+
1415
import jakarta.persistence.EntityManagerFactory;
1516
import jakarta.persistence.Persistence;
1617

18+
import org.hibernate.HibernateException;
1719
import org.hibernate.cfg.AvailableSettings;
1820
import org.hibernate.service.spi.ServiceException;
1921

2022
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
2123
import org.junit.jupiter.api.Assertions;
2224
import org.junit.jupiter.api.Test;
2325

26+
import static org.junit.jupiter.api.Assertions.fail;
27+
2428
/**
2529
* Test to verify that a dump configuration error results in an exception being
2630
* thrown even when booting via the standard JPA boostrap API.
@@ -42,6 +46,17 @@ public void exceptionOnIllegalPUWithoutProviderTest() {
4246
bootstrapPersistenceUnit( "IntentionallyBrokenWihoutExplicitProvider" ) );
4347
}
4448

49+
@Test
50+
public void missingClassPUTest() {
51+
try {
52+
bootstrapPersistenceUnit( "IntentionallyMissingClass" );
53+
fail("A HibernateException due to a missing class in the persistence.xml should have been thrown");
54+
}
55+
catch (HibernateException e) {
56+
// Success
57+
}
58+
}
59+
4560
private void bootstrapPersistenceUnit(final String puName) {
4661
final Map<String, Object> properties = new HashMap<>();
4762
properties.put( AvailableSettings.CLASSLOADERS, Arrays.asList( new TestClassLoader() ) );
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.jpa.boot;
6+
7+
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.Id;
10+
import jakarta.persistence.OneToOne;
11+
12+
/**
13+
* @author Jan Schatteman
14+
*/
15+
@Entity(name = "Event")
16+
public class Event {
17+
@Id
18+
@OneToOne
19+
private EventId id;
20+
21+
public EventId getId() {
22+
return id;
23+
}
24+
25+
public void setId(EventId id) {
26+
this.id = id;
27+
}
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.jpa.boot;
6+
7+
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.GeneratedValue;
10+
import jakarta.persistence.Id;
11+
12+
/**
13+
* @author Jan Schatteman
14+
*/
15+
@Entity(name = "EventId")
16+
public class EventId {
17+
18+
@Id
19+
@GeneratedValue
20+
private Long id;
21+
22+
}

hibernate-core/src/test/resources/org/hibernate/orm/test/jpa/boot/META-INF/persistence.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@
2525
</properties>
2626
</persistence-unit>
2727

28+
<persistence-unit name="IntentionallyMissingClass">
29+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
30+
<class>org.hibernate.orm.test.jpa.boot.Event</class>
31+
</persistence-unit>
32+
2833
</persistence>

0 commit comments

Comments
 (0)