Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for hibernate.properties (long deprecated) #17538

Merged
merged 2 commits into from
Jun 2, 2021
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 @@ -9,11 +9,13 @@
import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -423,6 +425,7 @@ public void build(RecorderContext recorderContext, HibernateOrmRecorder recorder
BuildProducer<BeanContainerListenerBuildItem> beanContainerListener) throws Exception {

feature.produce(new FeatureBuildItem(Feature.HIBERNATE_ORM));
validateHibernatePropertiesNotUsed();

final boolean enableORM = hasEntities(jpaModel);
final boolean hibernateReactivePresent = capabilities.isPresent(Capability.HIBERNATE_REACTIVE);
Expand Down Expand Up @@ -472,6 +475,22 @@ public void build(RecorderContext recorderContext, HibernateOrmRecorder recorder
proxyDefinitions.getProxies())));
}

private void validateHibernatePropertiesNotUsed() {
try {
final Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(
"hibernate.properties");
if (resources.hasMoreElements()) {
final URL url = resources.nextElement();
throw new IllegalStateException(
"The Hibernate ORM configuration in Quarkus does not support sourcing configuration properties from resources named `hibernate.properties`,"
+ " and this is now expressly prohibited as such a file could lead to unpredictable semantics. Please remove it from `"
+ url.toExternalForm() + '`');
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@BuildStep
void handleNativeImageImportSql(BuildProducer<NativeImageResourceBuildItem> resources,
List<PersistenceUnitDescriptorBuildItem> descriptors,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.quarkus.hibernate.orm.config;

import static org.assertj.core.api.Assertions.assertThat;

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.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

/**
* Since we decided that we're no longer supporting to read an hibernate.properties resource,
* let's also test that this is made explicit.
* N.B. while we no longer parse the file during boot, there are other components in Hibernate ORM
* that look for it so this would lead to inconsistencies.
*/
public class NoHibernatePropertiesTest {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.assertException(t -> {
assertThat(t)
.isInstanceOf(IllegalStateException.class)
.hasMessageContainingAll(
"The Hibernate ORM configuration in Quarkus does not support sourcing configuration properties from resources named `hibernate.properties`");
})
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClass(MyEntity.class)
.addAsResource(new StringAsset(""), "hibernate.properties")
.addAsResource("application.properties"))
.overrideConfigKey("quarkus.datasource.devservices", "false");

@Test
public void testInvalidConfiguration() {
// deployment exception should happen first
Assertions.fail();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.hibernate.service.internal.ProvidedService;
import org.hibernate.service.spi.ServiceContributor;

import io.quarkus.hibernate.orm.runtime.boot.QuarkusEnvironment;
import io.quarkus.hibernate.orm.runtime.service.InitialInitiatorListProvider;

/**
Expand All @@ -42,13 +41,7 @@ public final class RecordableBootstrap extends StandardServiceRegistryBuilder {

public RecordableBootstrap(BootstrapServiceRegistry bootstrapServiceRegistry,
InitialInitiatorListProvider initialInitiatorsProvider) {
this(bootstrapServiceRegistry, initialProperties(), LoadedConfig.baseline(), initialInitiatorsProvider);
}

private static Map initialProperties() {
HashMap map = new HashMap();
map.putAll(QuarkusEnvironment.getInitialProperties());
return map;
this(bootstrapServiceRegistry, new HashMap(), LoadedConfig.baseline(), initialInitiatorsProvider);
}

private RecordableBootstrap(BootstrapServiceRegistry bootstrapServiceRegistry, Map properties,
Expand Down