Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,11 @@ private void processFkSecondPassesInOrder() {
if ( sp.isInPrimaryKey() ) {
final String referenceEntityName = sp.getReferencedEntityName();
final PersistentClass classMapping = getEntityBinding( referenceEntityName );
if ( classMapping == null ) {
throw new HibernateException(
"Primary key referenced an unknown entity : " + referenceEntityName
);
}
final String dependentTable = classMapping.getTable().getQualifiedTableName().render();
if ( !isADependencyOf.containsKey( dependentTable ) ) {
isADependencyOf.put( dependentTable, new HashSet<>() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

import org.hibernate.HibernateException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.service.spi.ServiceException;

import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Test to verify that a dump configuration error results in an exception being
* thrown even when booting via the standard JPA boostrap API.
Expand All @@ -32,16 +35,24 @@ public class BootFailureTest {

@Test
public void exceptionOnIllegalPUTest() {
Assertions.assertThrows( ServiceException.class, () ->
assertThrows( ServiceException.class, () ->
bootstrapPersistenceUnit( "IntentionallyBroken" ) );
}

@Test
public void exceptionOnIllegalPUWithoutProviderTest() {
Assertions.assertThrows( ServiceException.class, () ->
assertThrows( ServiceException.class, () ->
bootstrapPersistenceUnit( "IntentionallyBrokenWihoutExplicitProvider" ) );
}

@Test
public void missingClassPUTest() {
assertThrows( HibernateException.class, () ->
bootstrapPersistenceUnit( "IntentionallyMissingClass" ),
"A HibernateException due to a missing class in the persistence.xml should have been thrown"
);
}

private void bootstrapPersistenceUnit(final String puName) {
final Map<String, Object> properties = new HashMap<>();
properties.put( AvailableSettings.CLASSLOADERS, Arrays.asList( new TestClassLoader() ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.jpa.boot;


import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;

/**
* @author Jan Schatteman
*/
@Entity(name = "Event")
public class Event {
@Id
@OneToOne
private EventId id;

public EventId getId() {
return id;
}

public void setId(EventId id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.jpa.boot;


import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

/**
* @author Jan Schatteman
*/
@Entity(name = "EventId")
public class EventId {

@Id
@GeneratedValue
private Long id;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@
</properties>
</persistence-unit>

<persistence-unit name="IntentionallyMissingClass">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>org.hibernate.orm.test.jpa.boot.Event</class>
</persistence-unit>

</persistence>