Skip to content

Commit

Permalink
Align bytecode enhancement behavior on Quarkus in QuarkusLikeORMUnitT…
Browse files Browse the repository at this point in the history
…estCase
  • Loading branch information
yrodiere committed Jan 16, 2025
1 parent cdc83f9 commit cd329fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.hibernate.bugs;

import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
import org.hibernate.bytecode.enhance.spi.UnloadedField;
import org.hibernate.bytecode.enhance.spi.UnsupportedEnhancementStrategy;

public class QuarkusLikeEnhancementContext extends DefaultEnhancementContext {
@Override
public boolean doBiDirectionalAssociationManagement(final UnloadedField field) {
//Don't enable automatic association management as it's often too surprising.
//Also, there's several cases in which its semantics are of unspecified,
//such as what should happen when dealing with ordered collections.
return false;
}

@Override
public UnsupportedEnhancementStrategy getUnsupportedEnhancementStrategy() {
// We expect model classes to be enhanced.
// Lack of enhancement could lead to many problems,
// from bad performance, to Quarkus-specific optimizations causing errors/data loss,
// to incorrect generated bytecode (references to non-existing methods).
// If something prevents enhancement, it's just safer to have Hibernate ORM's enhancer fail
// with a clear error message pointing to the application class that needs to be fixed.
return UnsupportedEnhancementStrategy.FAIL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.hibernate.cfg.AvailableSettings;

import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
Expand Down Expand Up @@ -61,6 +62,7 @@
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext(QuarkusLikeEnhancementContext.class)
class QuarkusLikeORMUnitTestCase {

// Add your tests, using standard JUnit.
Expand Down

0 comments on commit cd329fe

Please sign in to comment.