Remove Hibernate substitutions and deprecated properties usage
This commit raises the baseline to Hibernate 6.5 for native support, which allows to remove remaining Hibernate substitutions as well as deprecated properties usage. Closes gh-32314
This commit is contained in:
parent
dfc053ad65
commit
2350c8a8f5
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 <a href="https://hibernate.atlassian.net/browse/HHH-17568">HHH-17568</a>
|
||||
*/
|
||||
@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<String, PropertyAccess> propertyAccessMap) {
|
||||
return null;
|
||||
}
|
||||
|
||||
static class SubstituteOnlyIfPresent implements Predicate<String> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<String> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue