diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java index 680449827e0e4..e13ac3ef3d543 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java @@ -104,6 +104,7 @@ import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem; import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.index.IndexingUtil; import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild; @@ -311,6 +312,7 @@ public void configurationDescriptorBuilding( BuildProducer nativeImageResources, BuildProducer hotDeploymentWatchedFiles, BuildProducer persistenceUnitDescriptors, + BuildProducer reflectiveMethods, List dbKindMetadataBuildItems) { if (!hasEntities(jpaModel)) { @@ -348,7 +350,7 @@ public void configurationDescriptorBuilding( handleHibernateORMWithNoPersistenceXml(hibernateOrmConfig, index, persistenceXmlDescriptors, jdbcDataSources, applicationArchivesBuildItem, launchMode.getLaunchMode(), jpaModel, capabilities, systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors, - dbKindMetadataBuildItems); + reflectiveMethods, dbKindMetadataBuildItems); } } @@ -824,6 +826,7 @@ private void handleHibernateORMWithNoPersistenceXml( BuildProducer nativeImageResources, BuildProducer hotDeploymentWatchedFiles, BuildProducer persistenceUnitDescriptors, + BuildProducer reflectiveMethods, List dbKindMetadataBuildItems) { if (!descriptors.isEmpty()) { if (hibernateOrmConfig.isAnyNonPersistenceXmlPropertySet()) { @@ -872,7 +875,7 @@ private void handleHibernateORMWithNoPersistenceXml( jpaModel.getXmlMappings(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME), jdbcDataSources, applicationArchivesBuildItem, launchMode, capabilities, systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors, - storageEngineCollector, dbKindMetadataBuildItems); + reflectiveMethods, storageEngineCollector, dbKindMetadataBuildItems); } else if (!modelClassesAndPackagesForDefaultPersistenceUnit.isEmpty() && (!hibernateOrmConfig.defaultPersistenceUnit().datasource().isPresent() || DataSourceUtil.isDefault(hibernateOrmConfig.defaultPersistenceUnit().datasource().get())) @@ -892,7 +895,7 @@ private void handleHibernateORMWithNoPersistenceXml( jpaModel.getXmlMappings(persistenceUnitEntry.getKey()), jdbcDataSources, applicationArchivesBuildItem, launchMode, capabilities, systemProperties, nativeImageResources, hotDeploymentWatchedFiles, persistenceUnitDescriptors, - storageEngineCollector, dbKindMetadataBuildItems); + reflectiveMethods, storageEngineCollector, dbKindMetadataBuildItems); } if (storageEngineCollector.size() > 1) { @@ -915,6 +918,7 @@ private static void producePersistenceUnitDescriptorFromConfig( BuildProducer nativeImageResources, BuildProducer hotDeploymentWatchedFiles, BuildProducer persistenceUnitDescriptors, + BuildProducer reflectiveMethods, Set storageEngineCollector, List dbKindMetadataBuildItems) { Optional jdbcDataSource = findJdbcDataSource(persistenceUnitName, persistenceUnitConfig, @@ -943,7 +947,7 @@ private static void producePersistenceUnitDescriptorFromConfig( MultiTenancyStrategy multiTenancyStrategy = getMultiTenancyStrategy(persistenceUnitConfig.multitenant()); collectDialectConfig(persistenceUnitName, persistenceUnitConfig, dbKindMetadataBuildItems, jdbcDataSource, multiTenancyStrategy, - systemProperties, descriptor.getProperties()::setProperty, storageEngineCollector); + systemProperties, reflectiveMethods, descriptor.getProperties()::setProperty, storageEngineCollector); // Physical Naming Strategy persistenceUnitConfig.physicalNamingStrategy().ifPresent( @@ -1134,6 +1138,7 @@ private static void collectDialectConfig(String persistenceUnitName, List dbKindMetadataBuildItems, Optional jdbcDataSource, MultiTenancyStrategy multiTenancyStrategy, BuildProducer systemProperties, + BuildProducer reflectiveMethods, BiConsumer puPropertiesCollector, Set storageEngineCollector) { Optional explicitDialect = persistenceUnitConfig.dialect().dialect(); Optional dbKind = jdbcDataSource.map(JdbcDataSourceBuildItem::getDbKind); @@ -1210,6 +1215,14 @@ private static void collectDialectConfig(String persistenceUnitName, if (dbProductVersion.isPresent()) { puPropertiesCollector.accept(AvailableSettings.JAKARTA_HBM2DDL_DB_VERSION, dbProductVersion.get()); } + + if ((dbKind.isPresent() && DatabaseKind.isPostgreSQL(dbKind.get()) + || (dialect.isPresent() && dialect.get().toLowerCase(Locale.ROOT).contains("postgres")))) { + // Workaround for https://hibernate.atlassian.net/browse/HHH-19063 + reflectiveMethods.produce(new ReflectiveMethodBuildItem( + "Accessed in org.hibernate.engine.jdbc.env.internal.DefaultSchemaNameResolver.determineAppropriateResolverDelegate", + true, "org.postgresql.jdbc.PgConnection", "getSchema")); + } } private static void collectDialectConfigForPersistenceXml(String persistenceUnitName,