Skip to content

Commit cd329fe

Browse files
committed
Align bytecode enhancement behavior on Quarkus in QuarkusLikeORMUnitTestCase
1 parent cdc83f9 commit cd329fe

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.hibernate.bugs;
2+
3+
import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
4+
import org.hibernate.bytecode.enhance.spi.UnloadedField;
5+
import org.hibernate.bytecode.enhance.spi.UnsupportedEnhancementStrategy;
6+
7+
public class QuarkusLikeEnhancementContext extends DefaultEnhancementContext {
8+
@Override
9+
public boolean doBiDirectionalAssociationManagement(final UnloadedField field) {
10+
//Don't enable automatic association management as it's often too surprising.
11+
//Also, there's several cases in which its semantics are of unspecified,
12+
//such as what should happen when dealing with ordered collections.
13+
return false;
14+
}
15+
16+
@Override
17+
public UnsupportedEnhancementStrategy getUnsupportedEnhancementStrategy() {
18+
// We expect model classes to be enhanced.
19+
// Lack of enhancement could lead to many problems,
20+
// from bad performance, to Quarkus-specific optimizations causing errors/data loss,
21+
// to incorrect generated bytecode (references to non-existing methods).
22+
// If something prevents enhancement, it's just safer to have Hibernate ORM's enhancer fail
23+
// with a clear error message pointing to the application class that needs to be fixed.
24+
return UnsupportedEnhancementStrategy.FAIL;
25+
}
26+
}

orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.hibernate.cfg.AvailableSettings;
1919

20+
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
2021
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
2122
import org.hibernate.testing.orm.junit.DomainModel;
2223
import org.hibernate.testing.orm.junit.ServiceRegistry;
@@ -61,6 +62,7 @@
6162
)
6263
@SessionFactory
6364
@BytecodeEnhanced
65+
@CustomEnhancementContext(QuarkusLikeEnhancementContext.class)
6466
class QuarkusLikeORMUnitTestCase {
6567

6668
// Add your tests, using standard JUnit.

0 commit comments

Comments
 (0)