Skip to content

Commit a3670af

Browse files
committed
4.x: Tests fail when upgrading to Hibernate 6.6.23.Final #10441
Signed-off-by: Jorge Bescos Gascon <[email protected]>
1 parent 9462ba0 commit a3670af

File tree

10 files changed

+129
-14
lines changed

10 files changed

+129
-14
lines changed

dependencies/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
<version.lib.h2>2.2.220</version.lib.h2>
7070
<version.lib.hamcrest>1.3</version.lib.hamcrest>
7171
<version.lib.handlebars>4.4.0</version.lib.handlebars>
72-
<version.lib.hibernate.family>6.3</version.lib.hibernate.family>
73-
<version.lib.hibernate>${version.lib.hibernate.family}.1.Final</version.lib.hibernate>
72+
<version.lib.hibernate.family>6.6</version.lib.hibernate.family>
73+
<version.lib.hibernate>${version.lib.hibernate.family}.29.Final</version.lib.hibernate>
7474
<version.lib.hibernate-validator>8.0.2.Final</version.lib.hibernate-validator>
7575
<version.lib.hikaricp>5.0.1</version.lib.hikaricp>
7676
<version.lib.hystrix>1.5.18</version.lib.hystrix>

integrations/cdi/hibernate-cdi/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979
<artifactId>svm</artifactId>
8080
<scope>provided</scope>
8181
</dependency>
82+
<dependency>
83+
<groupId>net.bytebuddy</groupId>
84+
<artifactId>byte-buddy</artifactId>
85+
<scope>provided</scope>
86+
</dependency>
8287

8388
<!-- Compile-scoped dependencies. -->
8489
<dependency>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.integrations.cdi.hibernate;
18+
19+
import java.util.Optional;
20+
21+
import com.oracle.svm.core.annotate.Alias;
22+
import com.oracle.svm.core.annotate.RecomputeFieldValue;
23+
import com.oracle.svm.core.annotate.Substitute;
24+
import com.oracle.svm.core.annotate.TargetClass;
25+
import net.bytebuddy.description.field.FieldDescription;
26+
import net.bytebuddy.description.method.MethodDescription;
27+
import net.bytebuddy.matcher.ElementMatcher;
28+
29+
@TargetClass(className = "org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext")
30+
@SuppressWarnings("checkstyle:StaticVariableName")
31+
final class ByteBuddyEnhancementContext {
32+
33+
@Alias
34+
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)
35+
private static ElementMatcher.Junction<MethodDescription> IS_GETTER;
36+
37+
@Substitute
38+
Optional<MethodDescription> resolveGetter(FieldDescription fieldDescription) {
39+
return Optional.empty();
40+
}
41+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.integrations.cdi.hibernate;
18+
19+
import java.util.Collection;
20+
import java.util.function.BiFunction;
21+
22+
import com.oracle.svm.core.annotate.Alias;
23+
import com.oracle.svm.core.annotate.RecomputeFieldValue;
24+
import com.oracle.svm.core.annotate.Substitute;
25+
import com.oracle.svm.core.annotate.TargetClass;
26+
import net.bytebuddy.ByteBuddy;
27+
import net.bytebuddy.NamingStrategy;
28+
import net.bytebuddy.description.type.TypeDefinition;
29+
import net.bytebuddy.description.type.TypeDescription;
30+
import net.bytebuddy.dynamic.DynamicType;
31+
32+
33+
@TargetClass(className = "org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper")
34+
@SuppressWarnings("checkstyle:StaticVariableName")
35+
final class ByteBuddyProxyHelper {
36+
37+
@Alias
38+
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)
39+
private static TypeDescription OBJECT;
40+
41+
@Substitute
42+
private BiFunction<ByteBuddy, NamingStrategy, DynamicType.Builder<?>> proxyBuilder(TypeDefinition persistentClass,
43+
Collection<? extends TypeDefinition> interfaces) {
44+
return null;
45+
}
46+
}

integrations/cdi/hibernate-cdi/src/main/java/io/helidon/integrations/cdi/hibernate/BytecodeProviderInitiator.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2024, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,13 @@
1616

1717
package io.helidon.integrations.cdi.hibernate;
1818

19+
import java.util.Map;
1920
import java.util.function.Predicate;
2021

2122
import com.oracle.svm.core.annotate.Substitute;
2223
import com.oracle.svm.core.annotate.TargetClass;
2324
import org.hibernate.bytecode.spi.BytecodeProvider;
25+
import org.hibernate.service.spi.ServiceRegistryImplementor;
2426

2527
/**
2628
* In native image, we force the usage of the no-op bytecode provider so no bytecode
@@ -34,17 +36,23 @@ private BytecodeProviderInitiator() {
3436
}
3537

3638
@Substitute
37-
public static BytecodeProvider buildBytecodeProvider(String providerName) {
39+
public static BytecodeProvider buildDefaultBytecodeProvider() {
3840
return new org.hibernate.bytecode.internal.none.BytecodeProviderImpl();
3941
}
4042

43+
@Substitute
44+
public BytecodeProvider initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
45+
return buildDefaultBytecodeProvider();
46+
}
47+
4148
static class SubstituteOnlyIfPresent implements Predicate<String> {
4249

4350
@Override
4451
public boolean test(String type) {
4552
try {
4653
Class<?> clazz = Class.forName(type, false, getClass().getClassLoader());
47-
clazz.getDeclaredMethod("buildBytecodeProvider", String.class);
54+
clazz.getDeclaredMethod("buildDefaultBytecodeProvider");
55+
clazz.getDeclaredMethod("initiateService", Map.class, ServiceRegistryImplementor.class);
4856
return true;
4957
} catch (ClassNotFoundException | NoClassDefFoundError | NoSuchMethodException ex) {
5058
return false;

integrations/cdi/hibernate-cdi/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
requires transitive jakarta.inject;
4040
requires jakarta.persistence;
4141
requires transitive jakarta.transaction;
42+
requires transitive net.bytebuddy;
4243
requires org.graalvm.nativeimage;
4344
requires transitive org.hibernate.orm.core;
4445

integrations/cdi/hibernate-cdi/src/main/resources/META-INF/native-image/io.helidon.integrations.cdi/helidon-integrations-cdi-hibernate/native-image.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2024 Oracle and/or its affiliates.
2+
# Copyright (c) 2024, 2025 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -14,4 +14,6 @@
1414
# limitations under the License.
1515
#
1616

17-
Args=-H:ReflectionConfigurationResources=${.}/reflect-config-additional.json
17+
Args=-H:ReflectionConfigurationResources=${.}/reflect-config-additional.json \
18+
-H:ClassInitialization=org.hibernate.bytecode.enhance.internal.bytebuddy.ByteBuddyEnhancementContext:run_time \
19+
-H:ClassInitialization=org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper:run_time

integrations/cdi/hibernate-cdi/src/main/resources/META-INF/native-image/io.helidon.integrations.cdi/helidon-integrations-cdi-hibernate/reflect-config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,5 +2147,13 @@
21472147
]
21482148
}
21492149
]
2150+
},
2151+
{
2152+
"name": "org.hibernate.event.spi.PostUpsertEventListener[]",
2153+
"allDeclaredConstructors": true,
2154+
"allPublicConstructors": true,
2155+
"allDeclaredMethods": true,
2156+
"allDeclaredFields": true,
2157+
"unsafeAllocated": true
21502158
}
21512159
]

integrations/cdi/jpa-cdi/src/test/java/io/helidon/integrations/cdi/jpa/chirp/TestJpaTransactionScopedSynchronizedEntityManager.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2019, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -292,9 +292,9 @@ void testJpaTransactionScopedSynchronizedEntityManager()
292292
assertThat(transactionScopedContext.isActive(), is(true));
293293

294294
// Remove the Author we successfully committed before. We
295-
// have to merge because author1 became detached a few lines
296-
// above.
297-
author1 = em.merge(author1);
295+
// have to find because author1 became detached a few lines
296+
// above and it is not allowed to attach it again with merge.
297+
author1 = em.find(Author.class, Integer.valueOf(1));
298298
assertThat(author1, notNullValue());
299299
assertThat(em.contains(author1), is(true));
300300
em.remove(author1);
@@ -313,13 +313,15 @@ void testJpaTransactionScopedSynchronizedEntityManager()
313313
// tables.
314314
assertTableRowCount(dataSource, "AUTHOR", 0);
315315

316-
// Start a new transaction, merge our detached author1, and
316+
// Start a new transaction, persist our detached author1, and
317317
// commit. This will bump the author's ID and put a row in
318318
// the database.
319319
tm.begin();
320320
assertThat(em.isJoinedToTransaction(), is(true));
321321
assertThat(transactionScopedContext.isActive(), is(true));
322-
author1 = em.merge(author1);
322+
author1 = new Author("Abraham Lincoln");
323+
em.persist(author1);
324+
em.merge(author1);
323325
tm.commit();
324326
assertThat(em.isJoinedToTransaction(), is(false));
325327
assertThat(em.contains(author1), is(false));

integrations/cdi/jpa-cdi/src/test/java/io/helidon/integrations/cdi/jpa/chirp/TestRollbackScenarios.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2019, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -276,6 +276,8 @@ void testRollbackScenarios()
276276
assertThat(tm.getStatus(), is(Status.STATUS_ACTIVE));
277277
assertThat(em.isJoinedToTransaction(), is(true));
278278
assertThat(em.contains(author), is(false));
279+
author = new Author("John Kennedy");
280+
em.persist(author);
279281
author = em.merge(author);
280282
em.remove(author);
281283
tm.commit();

0 commit comments

Comments
 (0)