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 @@ -2,11 +2,14 @@

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

import java.util.List;

import jakarta.inject.Inject;
import jakarta.transaction.Transactional;

import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
Expand All @@ -32,7 +35,9 @@ public class ConfigPropertiesTest {
.overrideConfigKey("quarkus.hibernate-orm.\"overrides\".packages", MyEntityForOverridesPU.class.getPackageName())
.overrideConfigKey("quarkus.hibernate-orm.\"overrides\".datasource", "<default>")
// Overrides to test that Quarkus configuration properties are taken into account
.overrideConfigKey("quarkus.hibernate-orm.\"overrides\".flush.mode", "always");
.overrideConfigKey("quarkus.hibernate-orm.\"overrides\".flush.mode", "always")
.overrideConfigKey("quarkus.hibernate-orm.\"overrides\".database.extra-physical-table-types",
"MATERIALIZED VIEW,FOREIGN TABLE");

@Inject
Session sessionForDefaultPU;
Expand All @@ -48,4 +53,19 @@ public void propertiesAffectingSession() {
assertThat(sessionForOverridesPU.getHibernateFlushMode()).isEqualTo(FlushMode.ALWAYS);
}

@Test
@Transactional
public void extraPhysicalTableTypes() {
Object extraPhysicalTableTypes = sessionForOverridesPU.getProperties()
.get(AvailableSettings.EXTRA_PHYSICAL_TABLE_TYPES);

assertThat(extraPhysicalTableTypes).isNotNull();
assertThat(extraPhysicalTableTypes).isInstanceOf(List.class);
Copy link
Member

Choose a reason for hiding this comment

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

BTW this test is wrong, you should expect a String here. Did you run the test locally before pushing?


@SuppressWarnings("unchecked")
List<String> tableTypes = (List<String>) extraPhysicalTableTypes;

assertThat(tableTypes).containsExactly("MATERIALIZED VIEW", "FOREIGN TABLE");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ private static void injectRuntimeConfiguration(HibernateOrmRuntimeConfigPersiste
"When using offline mode with `quarkus.hibernate-orm.database.start-offline=true`, the schema management strategy `quarkus.hibernate-orm.schema-management.strategy` must be unset or set to `none`");
}

// Pass extraPhysicalTableTypes configuration
List<String> extraPhysicalTableTypes = persistenceUnitConfig.schemaManagement().extraPhysicalTableTypes();
if (extraPhysicalTableTypes != null && !extraPhysicalTableTypes.isEmpty()) {
String extraTableTypesStr = String.join(",", extraPhysicalTableTypes);
runtimeSettingsBuilder.put(AvailableSettings.EXTRA_PHYSICAL_TABLE_TYPES, extraTableTypesStr);
}

runtimeSettingsBuilder.put(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION,
persistenceUnitConfig.database().generation().generation()
.orElse(generationStrategy));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.hibernate.orm.runtime;

import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -172,6 +173,20 @@ interface HibernateOrmConfigPersistenceUnitSchemaManagement {
*/
@WithDefault("false")
boolean haltOnError();

/**
* Additional database object types to include in schema management operations.
*
* By default, Hibernate ORM only considers tables and sequences when performing
* schema management operations.
* This setting allows you to specify additional database object types that should be included,
* such as "MATERIALIZED VIEW", "VIEW", or other database-specific object types.
*
* The exact supported values depend on the underlying database and dialect.
*
* @asciidoclet
*/
List<@WithConverter(TrimmedStringConverter.class) String> extraPhysicalTableTypes();
Copy link
Member

Choose a reason for hiding this comment

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

Tests are failing with this:

2025-09-15T08:11:55.6146595Z Caused by: io.smallrye.config.ConfigValidationException: Configuration validation failed:
2025-09-15T08:11:55.6147707Z 	java.util.NoSuchElementException: SRCFG00014: The config property quarkus.hibernate-orm.*.schema-management.extra-physical-table-types is required but it could not be found in any config source
2025-09-15T08:11:55.6149434Z 	java.util.NoSuchElementException: SRCFG00014: The config property quarkus.hibernate-orm.schema-management.extra-physical-table-types is required but it could not be found in any config source

So, as weird as it sounds, I think you need to make this change:

Suggested change
List<@WithConverter(TrimmedStringConverter.class) String> extraPhysicalTableTypes();
Optional<List<@WithConverter(TrimmedStringConverter.class) String>> extraPhysicalTableTypes();

... and adapt callers.

Copy link
Author

Choose a reason for hiding this comment

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

I tried locally however it does not work on my side.

Copy link
Contributor

Choose a reason for hiding this comment

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

What didn't work? This pattern is used throughout Quarkus

}

@ConfigGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ private static void injectRuntimeConfiguration(HibernateOrmRuntimeConfigPersiste
"When using offline mode with `quarkus.hibernate-orm.database.start-offline=true`, the schema management strategy `quarkus.hibernate-orm.schema-management.strategy` must be unset or set to `none`");
}

// Pass extraPhysicalTableTypes configuration
List<String> extraPhysicalTableTypes = persistenceUnitConfig.schemaManagement().extraPhysicalTableTypes();
if (extraPhysicalTableTypes != null && !extraPhysicalTableTypes.isEmpty()) {
String extraTableTypesStr = String.join(",", extraPhysicalTableTypes);
runtimeSettingsBuilder.put(AvailableSettings.EXTRA_PHYSICAL_TABLE_TYPES, extraTableTypesStr);
}

// Database
runtimeSettingsBuilder.put(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION,
persistenceUnitConfig.database().generation().generation()
Expand Down
Loading