diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/SpringHibernateJpaPersistenceProvider.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/SpringHibernateJpaPersistenceProvider.java index 511d55f0dd7..d7c46339593 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/SpringHibernateJpaPersistenceProvider.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/SpringHibernateJpaPersistenceProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.spi.PersistenceUnitInfo; import org.hibernate.bytecode.enhance.spi.EnhancementContext; import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; import org.hibernate.jpa.HibernatePersistenceProvider; import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor; @@ -43,16 +42,8 @@ import org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo; * @since 4.1 * @see Configuration#addPackage */ -@SuppressWarnings("removal") // for Environment properties on Hibernate 6.2 class SpringHibernateJpaPersistenceProvider extends HibernatePersistenceProvider { - static { - if (NativeDetector.inNativeImage()) { - System.setProperty(Environment.BYTECODE_PROVIDER, Environment.BYTECODE_PROVIDER_NAME_NONE); - System.setProperty(Environment.USE_REFLECTION_OPTIMIZER, Boolean.FALSE.toString()); - } - } - @Override @SuppressWarnings({"rawtypes", "unchecked"}) // on Hibernate 6 public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProvider.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProvider.java deleted file mode 100644 index bf506d2443c..00000000000 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2002-2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.orm.jpa.vendor; - -import java.util.Map; -import java.util.function.Predicate; - -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import org.hibernate.bytecode.spi.ReflectionOptimizer; -import org.hibernate.property.access.spi.PropertyAccess; - -/** - * Hibernate 6.3+ substitution designed to leniently return {@code null}, as authorized by the API, to avoid throwing an - * {@code HibernateException}. - * - * @author Sebastien Deleuze - * @since 6.1 - * @see HHH-17568 - */ -@TargetClass(className = "org.hibernate.bytecode.internal.none.BytecodeProviderImpl", onlyWith = Target_BytecodeProvider.SubstituteOnlyIfPresent.class) -final class Target_BytecodeProvider { - - @Substitute - @SuppressWarnings("NullAway") - public ReflectionOptimizer getReflectionOptimizer(Class clazz, Map propertyAccessMap) { - return null; - } - - static class SubstituteOnlyIfPresent implements Predicate { - - @Override - public boolean test(String type) { - try { - Class clazz = Class.forName(type, false, getClass().getClassLoader()); - clazz.getDeclaredMethod("getReflectionOptimizer", Class.class, Map.class); - return true; - } - catch (ClassNotFoundException | NoClassDefFoundError | NoSuchMethodException ex) { - return false; - } - } - } - -} diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProviderInitiator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProviderInitiator.java deleted file mode 100644 index abda82e793a..00000000000 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProviderInitiator.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2002-2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.orm.jpa.vendor; - -import java.util.function.Predicate; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.RecomputeFieldValue; -import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import org.hibernate.bytecode.spi.BytecodeProvider; - -/** - * Hibernate substitution designed to prevent ByteBuddy reachability on native, and to enforce the - * usage of {@code org.hibernate.bytecode.internal.none.BytecodeProviderImpl} with Hibernate 6.3+. - * - * @author Sebastien Deleuze - * @since 6.1 - */ -@TargetClass(className = "org.hibernate.bytecode.internal.BytecodeProviderInitiator", onlyWith = Target_BytecodeProviderInitiator.SubstituteOnlyIfPresent.class) -final class Target_BytecodeProviderInitiator { - - @Alias - @SuppressWarnings("NullAway") - public static String BYTECODE_PROVIDER_NAME_NONE; - - @Alias - @RecomputeFieldValue(kind = Kind.FromAlias) - public static String BYTECODE_PROVIDER_NAME_DEFAULT = BYTECODE_PROVIDER_NAME_NONE; - - @Substitute - public static BytecodeProvider buildBytecodeProvider(String providerName) { - return new org.hibernate.bytecode.internal.none.BytecodeProviderImpl(); - } - - static class SubstituteOnlyIfPresent implements Predicate { - - @Override - public boolean test(String type) { - try { - Class clazz = Class.forName(type, false, getClass().getClassLoader()); - clazz.getDeclaredMethod("buildBytecodeProvider", String.class); - clazz.getField("BYTECODE_PROVIDER_NAME_NONE"); - clazz.getField("BYTECODE_PROVIDER_NAME_DEFAULT"); - return true; - } - catch (ClassNotFoundException | NoClassDefFoundError | NoSuchMethodException | NoSuchFieldException ex) { - return false; - } - } - } - -}