Skip to content

Commit e8e14bb

Browse files
Disable query startup checking during AOT and tweak hibernate logs.
Next to explicitly disabling query checks during AOT we now use an internal Dialect serving for required JdbcSettings.DIALECT. The name of the dialect is printed on info level via the JdbcEnvironment. Providing a meaningful name helps users understand better what is going on. See: #4068
1 parent 5ae90e4 commit e8e14bb

File tree

1 file changed

+14
-4
lines changed
  • spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot

1 file changed

+14
-4
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/aot/AotMetamodel.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131

3232
import org.hibernate.cfg.JdbcSettings;
3333
import org.hibernate.cfg.PersistenceSettings;
34-
import org.hibernate.dialect.H2Dialect;
34+
import org.hibernate.cfg.QuerySettings;
35+
import org.hibernate.dialect.Dialect;
3536
import org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl;
3637
import org.hibernate.jpa.HibernatePersistenceProvider;
3738
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
3839
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;
3940
import org.jspecify.annotations.Nullable;
40-
4141
import org.springframework.data.util.Lazy;
4242
import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypes;
4343
import org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo;
@@ -82,11 +82,12 @@ public AotMetamodel(PersistenceUnitInfo unitInfo) {
8282
static Lazy<EntityManagerFactory> init(Supplier<PersistenceUnitInfoDescriptor> unitInfo) {
8383

8484
return Lazy.of(() -> new EntityManagerFactoryBuilderImpl(unitInfo.get(),
85-
Map.of(JdbcSettings.DIALECT, H2Dialect.class.getName(), //
85+
Map.of(JdbcSettings.DIALECT, SpringDataJpaAotDialect.INSTANCE, //
8686
JdbcSettings.ALLOW_METADATA_ON_BOOT, false, //
8787
JdbcSettings.CONNECTION_PROVIDER, new UserSuppliedConnectionProviderImpl(), //
88+
QuerySettings.QUERY_STARTUP_CHECKING, false, //
8889
PersistenceSettings.JPA_CALLBACKS_ENABLED, false))
89-
.build());
90+
.build());
9091
}
9192

9293
private Metamodel getMetamodel() {
@@ -130,4 +131,13 @@ public EntityManagerFactory getEntityManagerFactory() {
130131
return entityManagerFactory.get();
131132
}
132133

134+
/**
135+
* A {@link Dialect} to satisfy the bootstrap requirements of {@link JdbcSettings#DIALECT} during the AOT Phase. Printed
136+
* to log files (info level) when the {@link org.hibernate.engine.jdbc.env.spi.JdbcEnvironment} is created.
137+
*/
138+
@SuppressWarnings("deprecation")
139+
static class SpringDataJpaAotDialect extends Dialect {
140+
static SpringDataJpaAotDialect INSTANCE = new SpringDataJpaAotDialect();
141+
}
142+
133143
}

0 commit comments

Comments
 (0)