Skip to content

Commit

Permalink
Work around no longer evaluated hibernate.properties.
Browse files Browse the repository at this point in the history
the bytecode provider property is no longer supported so we need to bypass the default implementation to avoid failures with bytebuddy.
  • Loading branch information
christophstrobl committed Apr 12, 2024
1 parent 731e8f1 commit 3e7e7ae
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dependencies {
testImplementation 'org.jboss.logging:jboss-logging:3.5.0.Final'

testImplementation 'ch.qos.logback:logback-classic:1.4.5'
testCompileOnly("net.bytebuddy:byte-buddy:1.12.10")
testCompileOnly("org.graalvm.nativeimage:graal-hotspot-library:22.0.0")
}

task updateGeneratedMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package org_hibernate_orm.hibernate_core;

import java.util.Map;

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;

@TargetClass(className = "org.hibernate.bytecode.internal.none.BytecodeProviderImpl")
final class Target_BytecodeProvider {

@Substitute
public ReflectionOptimizer getReflectionOptimizer(Class<?> clazz, Map<String, PropertyAccess> propertyAccessMap) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package org_hibernate_orm.hibernate_core;

import java.lang.reflect.Method;
import java.util.Set;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import net.bytebuddy.ClassFileVersion;
import org.hibernate.HibernateException;
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
import org.hibernate.bytecode.enhance.spi.Enhancer;
import org.hibernate.bytecode.spi.BasicProxyFactory;
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.type.CompositeType;

@TargetClass(className = "org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl")
final class Target_BytecodeProviderImpl {

@Substitute
public Target_BytecodeProviderImpl() {

}

@Substitute
public Target_BytecodeProviderImpl(ClassFileVersion targetCompatibleJVM) {

}

@Substitute
public ProxyFactoryFactory getProxyFactoryFactory() {
return new ProxyFactoryFactory() {
@Override
public ProxyFactory buildProxyFactory(SessionFactoryImplementor sessionFactory) {
return new ProxyFactory() {
@Override
public void postInstantiate(
String entityName,
Class<?> persistentClass,
Set<Class<?>> interfaces,
Method getIdentifierMethod,
Method setIdentifierMethod,
CompositeType componentIdType) {
}

@Override
public HibernateProxy getProxy(Object id, SharedSessionContractImplementor session) throws HibernateException {
throw new HibernateException( "Generation of HibernateProxy instances at runtime is not allowed when the configured BytecodeProvider is 'none'; your model requires a more advanced BytecodeProvider to be enabled." );
}
};
}

@Override
public BasicProxyFactory buildBasicProxyFactory(Class superClassOrInterface) {
return new BasicProxyFactory() {
@Override
public Object getProxy() {
throw new HibernateException( "NoneBasicProxyFactory is unable to generate a BasicProxy for type " + superClassOrInterface + ". Enable a different BytecodeProvider." );
}
};
}
};
}


@Substitute
public ReflectionOptimizer getReflectionOptimizer(
Class clazz,
String[] getterNames,
String[] setterNames,
Class[] types) {
throw new HibernateException( "Using the ReflectionOptimizer is not possible when the configured BytecodeProvider is 'none'. Use a different BytecodeProvider" );
}

@Substitute
public Enhancer getEnhancer(EnhancementContext enhancementContext) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package org_hibernate_orm.hibernate_core;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import org.hibernate.bytecode.spi.BytecodeProvider;

import static com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;

@TargetClass(className = "org.hibernate.bytecode.internal.BytecodeProviderInitiator")
final class Target_BytecodeProviderInitiator {

@Alias
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 buildDefaultBytecodeProvider() {
return new org.hibernate.bytecode.internal.none.BytecodeProviderImpl();
}

@Substitute
public static BytecodeProvider getBytecodeProvider(Iterable<BytecodeProvider> bytecodeProviders) {
return new org.hibernate.bytecode.internal.none.BytecodeProviderImpl();
}

}

0 comments on commit 3e7e7ae

Please sign in to comment.