HHH-17460 - Ongoing JPA 32 work

* Fix binding of `@IdClass` with generic property on the entity side
* Small cleanups to generics logic
This commit is contained in:
Marco Belladelli 2024-03-19 11:15:51 +01:00 committed by Steve Ebersole
parent 46cb96c35d
commit 6260941790
4 changed files with 13 additions and 9 deletions

View File

@ -382,15 +382,15 @@ public class ClassPropertyHolder extends AbstractPropertyHolder {
ClassDetails classDetails, ClassDetails classDetails,
String accessType, String accessType,
Map<String, MemberDetails> members) { Map<String, MemberDetails> members) {
final List<MemberDetails> collectedMembers = new ArrayList<>( switch ( accessType ) { final List<? extends MemberDetails> collectedMembers = switch ( accessType ) {
case ACCESS_FIELD -> classDetails.getFields(); case ACCESS_FIELD -> classDetails.getFields();
case ACCESS_PROPERTY -> classDetails.getMethods(); case ACCESS_PROPERTY -> classDetails.getMethods();
case ACCESS_RECORD -> classDetails.getRecordComponents(); case ACCESS_RECORD -> classDetails.getRecordComponents();
default -> throw new IllegalArgumentException( "Unknown access type " + accessType ); default -> throw new IllegalArgumentException( "Unknown access type " + accessType );
} ); };
members.putAll( collectedMembers.stream() collectedMembers.stream()
.filter( MemberDetails::isPersistable ) .filter( MemberDetails::isPersistable )
.collect( Collectors.toMap( MemberDetails::resolveAttributeName, item -> item ) ) ); .forEach( member -> members.put( member.resolveAttributeName(), member ) );
} }
private static void setTypeName(Value value, String typeName) { private static void setTypeName(Value value, String typeName) {

View File

@ -316,6 +316,7 @@ public class EmbeddableBinder {
inferredData, inferredData,
null, null,
propertyAccessor, propertyAccessor,
null,
isNullable, isNullable,
entityBinder, entityBinder,
isComponentEmbedded, isComponentEmbedded,
@ -335,6 +336,7 @@ public class EmbeddableBinder {
PropertyData inferredData, PropertyData inferredData,
PropertyData baseInferredData, //base inferred data correspond to the entity reproducing inferredData's properties (ie IdClass) PropertyData baseInferredData, //base inferred data correspond to the entity reproducing inferredData's properties (ie IdClass)
AccessType propertyAccessor, AccessType propertyAccessor,
ClassDetails entityAtStake,
boolean isNullable, boolean isNullable,
EntityBinder entityBinder, EntityBinder entityBinder,
boolean isComponentEmbedded, boolean isComponentEmbedded,
@ -438,7 +440,7 @@ public class EmbeddableBinder {
} }
final List<PropertyData> baseClassElements = final List<PropertyData> baseClassElements =
collectBaseClassElements( baseInferredData, propertyAccessor, context, annotatedType ); collectBaseClassElements( baseInferredData, propertyAccessor, context, entityAtStake );
if ( baseClassElements != null if ( baseClassElements != null
//useful to avoid breaking pre JPA 2 mappings //useful to avoid breaking pre JPA 2 mappings
&& !hasAnnotationsOnIdClass( annotatedType ) ) { && !hasAnnotationsOnIdClass( annotatedType ) ) {
@ -729,7 +731,7 @@ public class EmbeddableBinder {
PropertyData baseInferredData, PropertyData baseInferredData,
AccessType propertyAccessor, AccessType propertyAccessor,
MetadataBuildingContext context, MetadataBuildingContext context,
TypeDetails annotatedClass) { ClassDetails entityAtStake) {
if ( baseInferredData != null ) { if ( baseInferredData != null ) {
final List<PropertyData> baseClassElements = new ArrayList<>(); final List<PropertyData> baseClassElements = new ArrayList<>();
// iterate from base returned class up hierarchy to handle cases where the @Id attributes // iterate from base returned class up hierarchy to handle cases where the @Id attributes
@ -738,7 +740,7 @@ public class EmbeddableBinder {
while ( !Object.class.getName().equals( baseReturnedClassOrElement.getName() ) ) { while ( !Object.class.getName().equals( baseReturnedClassOrElement.getName() ) ) {
final PropertyContainer container = new PropertyContainer( final PropertyContainer container = new PropertyContainer(
baseReturnedClassOrElement.determineRawClass(), baseReturnedClassOrElement.determineRawClass(),
annotatedClass, entityAtStake,
propertyAccessor propertyAccessor
); );
addElementsOfClass( baseClassElements, container, context ); addElementsOfClass( baseClassElements, container, context );

View File

@ -598,6 +598,7 @@ public class EntityBinder {
), ),
baseInferredData, baseInferredData,
propertyAccessor, propertyAccessor,
annotatedClass,
false, false,
this, this,
true, true,
@ -696,6 +697,7 @@ public class EntityBinder {
inferredData, inferredData,
baseInferredData, baseInferredData,
propertyAccessor, propertyAccessor,
annotatedClass,
false, false,
this, this,
true, true,

View File

@ -106,7 +106,7 @@ public class PropertyInferredData implements PropertyData {
return new ClassTypeDetailsImpl( legacyAnnotationUsage.getClassDetails( "value" ), TypeDetails.Kind.CLASS ); return new ClassTypeDetailsImpl( legacyAnnotationUsage.getClassDetails( "value" ), TypeDetails.Kind.CLASS );
} }
return propertyMember.getAssociatedType().determineRelativeType( ownerType ); return propertyMember.resolveRelativeAssociatedType( ownerType );
} }
@Override @Override