HHH-17504 - Ongoing JPA 32 work HHH-17350 - Work on hibernate-models, XSD and JAXB HHH-16114 - Improve boot metamodel binding HHH-15996 - Develop an abstraction for Annotation in annotation processing HHH-16012 - Develop an abstraction for domain model Class refs HHH-15997 - Support for dynamic models in orm.xml HHH-15698 - Support for entity-name in mapping.xsd

This commit is contained in:
Andrea Boriero 2024-03-08 12:23:48 +01:00 committed by Steve Ebersole
parent 6099505ad1
commit 33c6e8284b
2 changed files with 31 additions and 23 deletions

View File

@ -772,29 +772,13 @@ public class BasicValueBinder implements JdbcTypeIndicators {
private void prepareBasicAttribute( private void prepareBasicAttribute(
String declaringClassName, String declaringClassName,
MemberDetails attributeMember, MemberDetails attributeMember,
TypeDetails attributeTypeDetails) { TypeDetails attributeType) {
final Class<Object> javaTypeClass = attributeTypeDetails.determineRawClass().toJavaClass(); final Class<Object> javaTypeClass = attributeType.determineRawClass().toJavaClass();
implicitJavaTypeAccess = ( typeConfiguration -> { implicitJavaTypeAccess = ( typeConfiguration -> {
final java.lang.reflect.Type attributeType = attributeTypeDetails.determineRawClass().toJavaClass(); if ( attributeType.getTypeKind() == TypeDetails.Kind.PARAMETERIZED_TYPE ) {
if ( attributeTypeDetails instanceof ParameterizedTypeDetails ) { return ParameterizedTypeImpl.from( attributeType.asParameterizedType() );
final List<TypeDetails> arguments = attributeTypeDetails.asParameterizedType().getArguments();
final int argumentsSize = arguments.size();
final java.lang.reflect.Type[] argumentTypes = new java.lang.reflect.Type[argumentsSize];
for ( int i = 0; i < argumentsSize; i++ ) {
argumentTypes[i] = arguments.get( i ).determineRawClass().toJavaClass();
}
final TypeDetails owner = attributeTypeDetails.asParameterizedType().getOwner();
final java.lang.reflect.Type ownerType;
if ( owner != null ) {
ownerType = owner.determineRawClass().toJavaClass();
}
else {
ownerType = null;
}
return new ParameterizedTypeImpl( attributeType, argumentTypes, ownerType );
} }
return attributeType; return attributeType.determineRawClass().toJavaClass();
} ); } );
//noinspection deprecation //noinspection deprecation
@ -817,7 +801,7 @@ public class BasicValueBinder implements JdbcTypeIndicators {
final AnnotationUsage<Enumerated> enumeratedAnn = attributeMember.getAnnotationUsage( Enumerated.class ); final AnnotationUsage<Enumerated> enumeratedAnn = attributeMember.getAnnotationUsage( Enumerated.class );
if ( enumeratedAnn != null ) { if ( enumeratedAnn != null ) {
this.enumType = enumeratedAnn.getEnum( "value" ); this.enumType = enumeratedAnn.getEnum( "value" );
if ( canUseEnumerated( attributeTypeDetails, javaTypeClass ) ) { if ( canUseEnumerated( attributeType, javaTypeClass ) ) {
if ( this.enumType == null ) { if ( this.enumType == null ) {
throw new IllegalStateException( throw new IllegalStateException(
"jakarta.persistence.EnumType was null on @jakarta.persistence.Enumerated " + "jakarta.persistence.EnumType was null on @jakarta.persistence.Enumerated " +
@ -831,7 +815,7 @@ public class BasicValueBinder implements JdbcTypeIndicators {
"Property '%s.%s' is annotated '@Enumerated' but its type '%s' is not an enum", "Property '%s.%s' is annotated '@Enumerated' but its type '%s' is not an enum",
declaringClassName, declaringClassName,
attributeMember.getName(), attributeMember.getName(),
attributeTypeDetails.getName() attributeType.getName()
) )
); );
} }

View File

@ -9,9 +9,13 @@ package org.hibernate.type.internal;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.StringJoiner; import java.util.StringJoiner;
import org.hibernate.models.spi.ParameterizedTypeDetails;
import org.hibernate.models.spi.TypeDetails;
public class ParameterizedTypeImpl implements ParameterizedType { public class ParameterizedTypeImpl implements ParameterizedType {
private final Type[] substTypeArgs; private final Type[] substTypeArgs;
@ -24,6 +28,26 @@ public class ParameterizedTypeImpl implements ParameterizedType {
this.ownerType = ownerType; this.ownerType = ownerType;
} }
public static ParameterizedTypeImpl from(ParameterizedTypeDetails typeDetails) {
final java.lang.reflect.Type attributeType = typeDetails.determineRawClass().toJavaClass();
final List<TypeDetails> arguments = typeDetails.asParameterizedType().getArguments();
final int argumentsSize = arguments.size();
final java.lang.reflect.Type[] argumentTypes = new java.lang.reflect.Type[argumentsSize];
for ( int i = 0; i < argumentsSize; i++ ) {
argumentTypes[i] = arguments.get( i ).determineRawClass().toJavaClass();
}
final TypeDetails owner = typeDetails.asParameterizedType().getOwner();
final java.lang.reflect.Type ownerType;
if ( owner != null ) {
ownerType = owner.determineRawClass().toJavaClass();
}
else {
ownerType = null;
}
return new ParameterizedTypeImpl( attributeType, argumentTypes, ownerType );
}
public Type[] getActualTypeArguments() { public Type[] getActualTypeArguments() {
return substTypeArgs; return substTypeArgs;
} }