HHH-16952 Disable enhancement expectation for attributes annotated with @Embedded when the type is not annotated with @Embeddable

This commit is contained in:
Christian Beikov 2023-08-28 19:05:56 +02:00
parent 4ba39b70c7
commit a8a4ff2af0
2 changed files with 25 additions and 7 deletions

View File

@ -69,7 +69,7 @@ class ByteBuddyEnhancementContext {
}
public boolean isCompositeField(AnnotatedFieldDescription field) {
return isCompositeClass( field.getType().asErasure() ) || field.hasAnnotation( Embedded.class );
return isCompositeClass( field.getType().asErasure() );
}
public AnnotatedFieldDescription[] order(AnnotatedFieldDescription[] persistentFields) {

View File

@ -13,30 +13,46 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@JiraKey( "HHH-16774" )
@JiraKey( "HHH-16952" )
@RunWith( BytecodeEnhancerRunner.class )
public class DirtyTrackingEmbeddableTest {
@Test
public void test() {
SimpleEntity entity = new SimpleEntity();
Address address = new Address();
entity.address = address;
Address1 address1 = new Address1();
entity.address1 = address1;
Address2 address2 = new Address2();
entity.address2 = address2;
EnhancerTestUtils.clearDirtyTracking( entity );
// testing composite object
address.city = "Arendal";
EnhancerTestUtils.checkDirtyTracking( entity, "address" );
address1.city = "Arendal";
address2.city = "Arendal";
// In 6.2, we can't change the SPI to make HHH-16952 possible,
// but we make sure to at least don't fail with an exception
EnhancerTestUtils.checkDirtyTracking( entity, "address1" );
EnhancerTestUtils.clearDirtyTracking( entity );
}
// --- //
@Embeddable
private static class Address {
private static class Address1 {
String street1;
String street2;
String city;
String state;
String zip;
String phone;
}
private static class Address2 {
String street1;
String street2;
String city;
@ -53,7 +69,9 @@ public class DirtyTrackingEmbeddableTest {
String name;
Address address;
Address1 address1;
@Embedded
Address2 address2;
}
}