Skip to content

Commit 6a841c8

Browse files
christophstroblfniephaus
authored andcommitted
Work around no longer evaluated hibernate.properties.
the bytecode provider property is no longer supported so we need to bypass the default implementation to avoid failures with bytebuddy.
1 parent 8a207e5 commit 6a841c8

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed

tests/src/org.hibernate.orm/hibernate-core/6.5.0.CR1/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ dependencies {
2121
testImplementation 'org.jboss.logging:jboss-logging:3.5.0.Final'
2222

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

2628
task updateGeneratedMetadata {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright and related rights waived via CC0
3+
*
4+
* You should have received a copy of the CC0 legalcode along with this
5+
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
6+
*/
7+
package org_hibernate_orm.hibernate_core;
8+
9+
import java.util.Map;
10+
11+
import com.oracle.svm.core.annotate.Substitute;
12+
import com.oracle.svm.core.annotate.TargetClass;
13+
import org.hibernate.bytecode.spi.ReflectionOptimizer;
14+
import org.hibernate.property.access.spi.PropertyAccess;
15+
16+
@TargetClass(className = "org.hibernate.bytecode.internal.none.BytecodeProviderImpl")
17+
final class Target_BytecodeProvider {
18+
19+
@Substitute
20+
public ReflectionOptimizer getReflectionOptimizer(Class<?> clazz, Map<String, PropertyAccess> propertyAccessMap) {
21+
return null;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright and related rights waived via CC0
3+
*
4+
* You should have received a copy of the CC0 legalcode along with this
5+
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
6+
*/
7+
package org_hibernate_orm.hibernate_core;
8+
9+
import java.lang.reflect.Method;
10+
import java.util.Set;
11+
12+
import com.oracle.svm.core.annotate.Substitute;
13+
import com.oracle.svm.core.annotate.TargetClass;
14+
import net.bytebuddy.ClassFileVersion;
15+
import org.hibernate.HibernateException;
16+
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
17+
import org.hibernate.bytecode.enhance.spi.Enhancer;
18+
import org.hibernate.bytecode.spi.BasicProxyFactory;
19+
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
20+
import org.hibernate.bytecode.spi.ReflectionOptimizer;
21+
import org.hibernate.engine.spi.SessionFactoryImplementor;
22+
import org.hibernate.engine.spi.SharedSessionContractImplementor;
23+
import org.hibernate.proxy.HibernateProxy;
24+
import org.hibernate.proxy.ProxyFactory;
25+
import org.hibernate.type.CompositeType;
26+
27+
@TargetClass(className = "org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl")
28+
final class Target_BytecodeProviderImpl {
29+
30+
@Substitute
31+
Target_BytecodeProviderImpl() {
32+
33+
}
34+
35+
@Substitute
36+
Target_BytecodeProviderImpl(ClassFileVersion targetCompatibleJVM) {
37+
38+
}
39+
40+
@Substitute
41+
public ProxyFactoryFactory getProxyFactoryFactory() {
42+
return new ProxyFactoryFactory() {
43+
@Override
44+
public ProxyFactory buildProxyFactory(SessionFactoryImplementor sessionFactory) {
45+
return new ProxyFactory() {
46+
@Override
47+
public void postInstantiate(
48+
String entityName,
49+
Class<?> persistentClass,
50+
Set<Class<?>> interfaces,
51+
Method getIdentifierMethod,
52+
Method setIdentifierMethod,
53+
CompositeType componentIdType) {
54+
}
55+
56+
@Override
57+
public HibernateProxy getProxy(Object id, SharedSessionContractImplementor session) throws HibernateException {
58+
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.");
59+
}
60+
};
61+
}
62+
63+
@Override
64+
public BasicProxyFactory buildBasicProxyFactory(Class superClassOrInterface) {
65+
return new BasicProxyFactory() {
66+
@Override
67+
public Object getProxy() {
68+
throw new HibernateException("NoneBasicProxyFactory is unable to generate a BasicProxy for type " + superClassOrInterface + ". Enable a different BytecodeProvider.");
69+
}
70+
};
71+
}
72+
};
73+
}
74+
75+
76+
@Substitute
77+
public ReflectionOptimizer getReflectionOptimizer(
78+
Class clazz,
79+
String[] getterNames,
80+
String[] setterNames,
81+
Class[] types) {
82+
throw new HibernateException("Using the ReflectionOptimizer is not possible when the configured BytecodeProvider is 'none'. Use a different BytecodeProvider");
83+
}
84+
85+
@Substitute
86+
public Enhancer getEnhancer(EnhancementContext enhancementContext) {
87+
return null;
88+
}
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright and related rights waived via CC0
3+
*
4+
* You should have received a copy of the CC0 legalcode along with this
5+
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
6+
*/
7+
package org_hibernate_orm.hibernate_core;
8+
9+
import com.oracle.svm.core.annotate.Substitute;
10+
import com.oracle.svm.core.annotate.TargetClass;
11+
import org.hibernate.bytecode.spi.BytecodeProvider;
12+
13+
@TargetClass(className = "org.hibernate.bytecode.internal.BytecodeProviderInitiator")
14+
final class Target_BytecodeProviderInitiator {
15+
16+
@Substitute
17+
public static BytecodeProvider buildDefaultBytecodeProvider() {
18+
return new org.hibernate.bytecode.internal.none.BytecodeProviderImpl();
19+
}
20+
21+
@Substitute
22+
public static BytecodeProvider getBytecodeProvider(Iterable<BytecodeProvider> bytecodeProviders) {
23+
return new org.hibernate.bytecode.internal.none.BytecodeProviderImpl();
24+
}
25+
}

0 commit comments

Comments
 (0)