Skip to content
Open
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 @@ -743,7 +743,12 @@ Deployments using CA-signed certificates or a truststore that already contains t
With the caches enabled, Hibernate's `SimpleTimestamper` kept every thread that opened a database session at 100% CPU after the system clock was moved backwards, until the clock caught up with the previously issued timestamp.

This change has no effect on the data stored or cached by {project_name}.
If you use a custom extension that relies on Hibernate's second-level or query cache, set `quarkus.hibernate-orm.second-level-caching-enabled=true` in `conf/quarkus.properties` and run `kc.sh build`.
The unused `org.hibernate.orm:hibernate-jcache`, `com.github.ben-manes.caffeine:jcache` and dependencies needed only for JCache, such as `javax.cache:cache-api`, are no longer bundled.
If you use a custom extension that relies on Hibernate's second-level or query cache, install `org.hibernate.orm:hibernate-jcache`, `com.github.ben-manes.caffeine:jcache`, `javax.cache:cache-api` and `com.typesafe:config` in the `providers` directory, using versions compatible with the bundled Hibernate ORM and Quarkus versions.
Do not duplicate dependencies already bundled with {project_name}, such as Hibernate ORM core and Caffeine core.
To re-enable caching by default, set `quarkus.hibernate-orm.second-level-caching-enabled=true` in `conf/quarkus.properties`.
Custom persistence units inherit this setting unless they explicitly set `hibernate.cache.use_second_level_cache` or `hibernate.cache.use_query_cache` in their `persistence.xml` properties.
Then run `kc.sh build`.
Comment on lines +747 to +751

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would even consider completely remove the migration steps and just say second-level cache is not supported any more, if we decide to make it a breaking change and target 27 only. But I'm open to discussion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't sound like a viable alternative, this is difficult to get right. I'd say remove it from 27.0 as a breaking change.

Did you plan to backport that change to 26.8?


=== In template strings, a `$` that does not start a placeholder is no longer corrupted
// https://github.com/keycloak/keycloak/issues/55326
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.LogHandlerBuildItem;
import io.quarkus.deployment.builditem.StaticInitConfigBuilderBuildItem;
import io.quarkus.hibernate.orm.deployment.HibernateOrmConfig;
import io.quarkus.hibernate.orm.deployment.JpaModelPersistenceUnitContributionBuildItem;
import io.quarkus.hibernate.orm.deployment.integration.HibernateOrmIntegrationRuntimeConfiguredBuildItem;
import io.quarkus.hibernate.orm.deployment.integration.HibernateOrmIntegrationStaticConfiguredBuildItem;
Expand Down Expand Up @@ -381,7 +382,7 @@
logger.infof("Multiple datasources are specified: %s", String.join(", ", datasources));
}

if (transactionManagerConfig.unsafeMultipleLastResources()

Check warning on line 385 in quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java

View workflow job for this annotation

GitHub Actions / Quarkus UT (ubuntu-latest)

unsafeMultipleLastResources() in io.quarkus.narayana.jta.runtime.TransactionManagerBuildTimeConfig has been deprecated and marked for removal
.orElse(UnsafeMultipleLastResourcesMode.DEFAULT) != UnsafeMultipleLastResourcesMode.FAIL) {
return;
}
Expand Down Expand Up @@ -516,7 +517,7 @@
@BuildStep
@Consume(CheckJdbcBuildStep.class)
@Consume(CheckMultipleDatasourcesBuildStep.class)
void produceUserDefinedPersistenceUnits(BuildProducer<AdditionalPersistenceUnitBuildItem> producer) {
void produceUserDefinedPersistenceUnits(HibernateOrmConfig hibernateOrmConfig, BuildProducer<AdditionalPersistenceUnitBuildItem> producer) {
PersistenceXmlParser parser = PersistenceXmlParser.create();
List<URL> urls = parser.getClassLoaderService().locateResources("META-INF/persistence.xml");
if (urls.isEmpty()) {
Expand Down Expand Up @@ -546,8 +547,11 @@
}

String datasourceName = getDatasourceNameFromPersistenceXml(descriptor);
String cachingEnabled = Boolean.toString(hibernateOrmConfig.defaultPersistenceUnit().secondLevelCachingEnabled());
AdditionalPersistenceUnitBuildItem.Builder builder = AdditionalPersistenceUnitBuildItem.builder(puName)
.dataSourceName(datasourceName);
.dataSourceName(datasourceName)
.property(AvailableSettings.USE_SECOND_LEVEL_CACHE, cachingEnabled)
.property(AvailableSettings.USE_QUERY_CACHE, cachingEnabled);
for (String className : descriptor.getManagedClassNames()) {
builder.managedClass(className);
}
Expand Down
10 changes: 10 additions & 0 deletions quarkus/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jcache</artifactId>
</exclusion>
<exclusion>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>jcache</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
22 changes: 22 additions & 0 deletions quarkus/tests/integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@
<version>${approvaltests.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jcache</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>jcache</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bc-fips</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,18 @@ public Class[] getClasses() {
public Map<String, String> getManifestResources() {
return Map.of("persistence.xml", "persistence.xml", "orm.xml", "orm.xml");
}

public static class CacheEnabled extends SingleNamedPuTestProvider {
@Override
public Map<String, String> getManifestResources() {
return Map.of("cached-persistence.xml", "persistence.xml", "orm.xml", "orm.xml");
}
}

public static class CacheDisabled extends SingleNamedPuTestProvider {
@Override
public Map<String, String> getManifestResources() {
return Map.of("uncached-persistence.xml", "persistence.xml", "orm.xml", "orm.xml");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
version="3.0">
<persistence-unit name="single-named-store" transaction-type="JTA">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
</properties>
</persistence-unit>
</persistence>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
version="3.0">
<persistence-unit name="single-named-store" transaction-type="JTA">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
</properties>
</persistence-unit>
</persistence>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.keycloak.it.junit5.extension.CLIResult;
import org.keycloak.it.junit5.extension.DistributionTest;
import org.keycloak.it.junit5.extension.KeycloakRunner;
import org.keycloak.it.junit5.extension.RawDistOnly;
import org.keycloak.it.junit5.extension.TestProvider;
import org.keycloak.it.utils.RawKeycloakDistribution;

import com.acme.provider.singlenamed.SingleNamedPuTestProvider;
import io.quarkus.test.junit.main.Launch;
Expand All @@ -17,10 +19,10 @@
@DistributionTest
@RawDistOnly(reason = "Containers are immutable")
@Tag(DistributionTest.SMOKE)
@TestProvider(SingleNamedPuTestProvider.class)
public class SingleNamedPuOrmXmlDistTest {

@Test
@TestProvider(SingleNamedPuTestProvider.class)
@Launch({"start-dev", "--db=dev-file", "--db-kind-single-named-store=dev-mem", "--log-level=org.hibernate.orm.jpa:debug,org.keycloak.quarkus.deployment.KeycloakProcessor:debug"})
void testSingleNamedPuWithOrmXmlLoaded(CLIResult cliResult) {
String output = cliResult.getOutput();
Expand All @@ -30,6 +32,8 @@ void testSingleNamedPuWithOrmXmlLoaded(CLIResult cliResult) {

assertTrue(singlePuBlock.contains("com.acme.provider.singlenamed.SingleNamedPuEntity"),
"SingleNamedPuEntity (from implicit orm.xml in single-PU archive) must be loaded into 'single-named-store' PU");
assertTrue(singlePuBlock.contains("hibernate.cache.use_second_level_cache: false"));
assertTrue(singlePuBlock.contains("hibernate.cache.use_query_cache: false"));

String defaultPuBlock = extractPersistenceUnitBlock(output, "<default>");
if (defaultPuBlock != null) {
Expand All @@ -40,6 +44,64 @@ void testSingleNamedPuWithOrmXmlLoaded(CLIResult cliResult) {
cliResult.assertStartedDevMode();
}

@Test
@TestProvider(SingleNamedPuTestProvider.CacheEnabled.class)
void cachingCanBeEnabledInCustomPersistenceUnit(KeycloakRunner runner) {
var distribution = runner.getDistribution(RawKeycloakDistribution.class);
installCachingDependencies(distribution);

var result = runner.run("start-dev", "--db=dev-file", "--db-kind-single-named-store=dev-mem",
"--log-level=org.hibernate.orm.jpa:debug,org.hibernate.orm.cache:debug");
assertCachingEnabled(result);
}

@Test
@TestProvider(SingleNamedPuTestProvider.class)
void customPersistenceUnitInheritsCachingConfiguration(KeycloakRunner runner) {
var distribution = runner.getDistribution(RawKeycloakDistribution.class);
installCachingDependencies(distribution);
distribution.setQuarkusProperty("quarkus.hibernate-orm.second-level-caching-enabled", "true");

var result = runner.run("start-dev", "--db=dev-file", "--db-kind-single-named-store=dev-mem",
"--log-level=org.hibernate.orm.jpa:debug,org.hibernate.orm.cache:debug");
assertCachingEnabled(result);
}

@Test
@TestProvider(SingleNamedPuTestProvider.CacheDisabled.class)
void cachingCanBeDisabledInCustomPersistenceUnit(KeycloakRunner runner) {
var distribution = runner.getDistribution(RawKeycloakDistribution.class);
installCachingDependencies(distribution);
distribution.setQuarkusProperty("quarkus.hibernate-orm.second-level-caching-enabled", "true");

var result = runner.run("start-dev", "--db=dev-file", "--db-kind-single-named-store=dev-mem",
"--log-level=org.hibernate.orm.jpa:debug");
result.assertStartedDevMode();

String singlePuBlock = extractPersistenceUnitBlock(result.getOutput(), "single-named-store");
assertNotNull(singlePuBlock, "'single-named-store' PU info block should be present");
assertTrue(singlePuBlock.contains("hibernate.cache.use_second_level_cache: false"));
assertTrue(singlePuBlock.contains("hibernate.cache.use_query_cache: false"));
}

private static void installCachingDependencies(RawKeycloakDistribution distribution) {
distribution.copyProvider("org.hibernate.orm", "hibernate-jcache");
distribution.copyProvider("com.github.ben-manes.caffeine", "jcache");
distribution.copyProvider("javax.cache", "cache-api");
distribution.copyProvider("com.typesafe", "config");
}

private static void assertCachingEnabled(CLIResult result) {
result.assertStartedDevMode();

String singlePuBlock = extractPersistenceUnitBlock(result.getOutput(), "single-named-store");
assertNotNull(singlePuBlock, "'single-named-store' PU info block should be present");
assertTrue(singlePuBlock.contains("hibernate.cache.use_second_level_cache: true"));
assertTrue(singlePuBlock.contains("hibernate.cache.use_query_cache: true"));
result.assertMessage("Missing cache region [default-update-timestamps-region]");
result.assertMessage("Missing cache region [default-query-results-region]");
}

private static String extractPersistenceUnitBlock(String output, String puName) {
String marker = "HHH008541: PersistenceUnitInfo [";
String nameToken = "name: " + puName;
Expand Down
Loading