HHH-17745 @HQL methods accepting embeddables

and replace usages of getJavaType().getTypeName(), since
using getTypeName() directly is much more freindly to the
annotation processor (as well as less verbose)
This commit is contained in:
Gavin King 2024-02-16 19:29:25 +01:00
parent eb11676479
commit f1e099b8e8
57 changed files with 188 additions and 103 deletions

View File

@ -66,9 +66,9 @@ public class TenantIdBinder implements AttributeBinder<TenantId> {
if ( !parameterJtd.getJavaTypeClass().equals( tenantIdTypeJtd.getJavaTypeClass() ) ) { if ( !parameterJtd.getJavaTypeClass().equals( tenantIdTypeJtd.getJavaTypeClass() ) ) {
throw new MappingException( throw new MappingException(
"all @TenantId fields must have the same type: " "all @TenantId fields must have the same type: "
+ parameterJtd.getJavaType().getTypeName() + parameterJtd.getTypeName()
+ " differs from " + " differs from "
+ tenantIdTypeJtd.getJavaType().getTypeName() + tenantIdTypeJtd.getTypeName()
); );
} }
} }

View File

@ -57,7 +57,7 @@ public class TypeDefinitionRegistryStandardImpl implements TypeDefinitionRegistr
return null; return null;
} }
return typeDefinitionMap.get( jtd.getJavaType().getTypeName() ); return typeDefinitionMap.get( jtd.getTypeName() );
} }
@Override @Override

View File

@ -782,11 +782,11 @@ public final class AnnotationBinder {
new JpaAttributeConverterImpl( bean, converterJtd, domainJtd, relationalJtd ); new JpaAttributeConverterImpl( bean, converterJtd, domainJtd, relationalJtd );
return new ConvertedBasicTypeImpl<>( return new ConvertedBasicTypeImpl<>(
ConverterDescriptor.TYPE_NAME_PREFIX ConverterDescriptor.TYPE_NAME_PREFIX
+ valueConverter.getConverterJavaType().getJavaType().getTypeName(), + valueConverter.getConverterJavaType().getTypeName(),
String.format( String.format(
"BasicType adapter for AttributeConverter<%s,%s>", "BasicType adapter for AttributeConverter<%s,%s>",
domainJtd.getJavaType().getTypeName(), domainJtd.getTypeName(),
relationalJtd.getJavaType().getTypeName() relationalJtd.getTypeName()
), ),
relationalJtd.getRecommendedJdbcType( typeConfiguration.getCurrentBaseSqlTypeIndicators() ), relationalJtd.getRecommendedJdbcType( typeConfiguration.getCurrentBaseSqlTypeIndicators() ),
valueConverter valueConverter

View File

@ -200,11 +200,11 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
this.legacyResolvedType = new CustomMutabilityConvertedBasicTypeImpl<>( this.legacyResolvedType = new CustomMutabilityConvertedBasicTypeImpl<>(
ConverterDescriptor.TYPE_NAME_PREFIX ConverterDescriptor.TYPE_NAME_PREFIX
+ valueConverter.getConverterJavaType().getJavaType().getTypeName(), + valueConverter.getConverterJavaType().getTypeName(),
String.format( String.format(
"BasicType adapter for AttributeConverter<%s,%s>", "BasicType adapter for AttributeConverter<%s,%s>",
domainJtd.getJavaType().getTypeName(), domainJtd.getTypeName(),
relationalJtd.getJavaType().getTypeName() relationalJtd.getTypeName()
), ),
jdbcType, jdbcType,
valueConverter, valueConverter,

View File

@ -91,7 +91,7 @@ public class UUIDGenerator implements IdentifierGenerator, StandardGenerator {
valueTransformer = UUIDJavaType.ToBytesTransformer.INSTANCE; valueTransformer = UUIDJavaType.ToBytesTransformer.INSTANCE;
} }
else { else {
throw new HibernateException( "Unanticipated return type [" + type.getReturnedClass().getName() + "] for UUID conversion" ); throw new HibernateException( "Unanticipated return type [" + type.getReturnedClassName() + "] for UUID conversion" );
} }
} }

View File

@ -772,11 +772,11 @@ public abstract class SimpleValue implements KeyValue {
// todo : cache the AttributeConverterTypeAdapter in case that AttributeConverter is applied multiple times. // todo : cache the AttributeConverterTypeAdapter in case that AttributeConverter is applied multiple times.
return new ConvertedBasicTypeImpl<>( return new ConvertedBasicTypeImpl<>(
TYPE_NAME_PREFIX TYPE_NAME_PREFIX
+ jpaAttributeConverter.getConverterJavaType().getJavaType().getTypeName(), + jpaAttributeConverter.getConverterJavaType().getTypeName(),
String.format( String.format(
"BasicType adapter for AttributeConverter<%s,%s>", "BasicType adapter for AttributeConverter<%s,%s>",
domainJavaType.getJavaType().getTypeName(), domainJavaType.getTypeName(),
relationalJavaType.getJavaType().getTypeName() relationalJavaType.getTypeName()
), ),
metadata.getTypeConfiguration().getJdbcTypeRegistry().getDescriptor( jdbcTypeCode ), metadata.getTypeConfiguration().getJdbcTypeRegistry().getDescriptor( jdbcTypeCode ),
jpaAttributeConverter jpaAttributeConverter

View File

@ -153,7 +153,7 @@ public class EmbeddableRepresentationStrategyPojo extends AbstractEmbeddableRepr
String.format( String.format(
Locale.ROOT, Locale.ROOT,
"Could not resolve PropertyAccess for attribute `%s#%s`", "Could not resolve PropertyAccess for attribute `%s#%s`",
getEmbeddableJavaType().getJavaType().getTypeName(), getEmbeddableJavaType().getTypeName(),
bootAttributeDescriptor.getName() bootAttributeDescriptor.getName()
) )
); );

View File

@ -330,7 +330,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
String.format( String.format(
Locale.ROOT, Locale.ROOT,
"Could not resolve PropertyAccess for attribute `%s#%s`", "Could not resolve PropertyAccess for attribute `%s#%s`",
mappedJtd.getJavaType().getTypeName(), mappedJtd.getTypeName(),
bootAttributeDescriptor.getName() bootAttributeDescriptor.getName()
) )
); );

View File

@ -141,7 +141,7 @@ public class SimpleNaturalIdMapping extends AbstractNaturalIdMapping implements
"Incoming natural-id value [%s (`%s`)] is not of expected type [`%s`] and could not be coerced", "Incoming natural-id value [%s (`%s`)] is not of expected type [`%s`] and could not be coerced",
naturalIdValue, naturalIdValue,
naturalIdValueClass.getName(), naturalIdValueClass.getName(),
getJavaType().getJavaType().getTypeName() getJavaType().getTypeName()
) )
); );
} }

View File

@ -592,7 +592,7 @@ public class ToOneAttributeMapping
final Collection collection = (Collection) value; final Collection collection = (Collection) value;
if ( propertyPath.equals( collection.getMappedByProperty() ) if ( propertyPath.equals( collection.getMappedByProperty() )
&& collection.getElement().getType().getName() && collection.getElement().getType().getName()
.equals( declaringType.getJavaType().getJavaType().getTypeName() ) ) { .equals( declaringType.getJavaType().getTypeName() ) ) {
return parentSelectablePath == null return parentSelectablePath == null
? SelectablePath.parse( property.getName() ) ? SelectablePath.parse( property.getName() )
: parentSelectablePath.append( property.getName() ); : parentSelectablePath.append( property.getName() );
@ -627,7 +627,7 @@ public class ToOneAttributeMapping
if (declaringTableGroupProducer.getNavigableRole().getLocalName().equals( oneToOne.getReferencedEntityName() ) if (declaringTableGroupProducer.getNavigableRole().getLocalName().equals( oneToOne.getReferencedEntityName() )
&& propertyPath.equals( oneToOne.getMappedByProperty() ) && propertyPath.equals( oneToOne.getMappedByProperty() )
&& oneToOne.getReferencedEntityName() && oneToOne.getReferencedEntityName()
.equals( declaringType.getJavaType().getJavaType().getTypeName() ) ) { .equals( declaringType.getJavaType().getTypeName() ) ) {
return parentSelectablePath == null return parentSelectablePath == null
? SelectablePath.parse( property.getName() ) ? SelectablePath.parse( property.getName() )
: parentSelectablePath.append( property.getName() ); : parentSelectablePath.append( property.getName() );
@ -1466,13 +1466,13 @@ public class ToOneAttributeMapping
where leve2Child is of type DerivedLevel2 while level2Parent of type Level2 where leve2Child is of type DerivedLevel2 while level2Parent of type Level2
for this reason we need the check entityMappingType.isSubclassEntityName( partMappingType.getMappedJavaType().getJavaType().getTypeName() ) for this reason we need the check entityMappingType.isSubclassEntityName( partMappingType.getMappedJavaType().getTypeName() )
to be sure that the referencedNavigablePath corresponds to leve2Child to be sure that the referencedNavigablePath corresponds to leve2Child
*/ */
while ( !( partMappingType instanceof EntityMappingType ) while ( !( partMappingType instanceof EntityMappingType )
|| ( partMappingType != entityMappingType || ( partMappingType != entityMappingType
&& !entityMappingType.getEntityPersister().isSubclassEntityName( partMappingType.getMappedJavaType().getJavaType().getTypeName() ) && !entityMappingType.getEntityPersister().isSubclassEntityName( partMappingType.getMappedJavaType().getTypeName() )
&& !( (EntityMappingType) partMappingType ).getEntityPersister().isSubclassEntityName( entityMappingType.getEntityName() ) ) ) { && !( (EntityMappingType) partMappingType ).getEntityPersister().isSubclassEntityName( entityMappingType.getEntityName() ) ) ) {
referencedNavigablePath = referencedNavigablePath.getParent(); referencedNavigablePath = referencedNavigablePath.getParent();
if ( referencedNavigablePath == null ) { if ( referencedNavigablePath == null ) {

View File

@ -15,7 +15,6 @@ import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor;
import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.metamodel.SingularAttribute; import jakarta.persistence.metamodel.SingularAttribute;
import jakarta.persistence.metamodel.Type;
/** /**
* Implementation of {@link jakarta.persistence.metamodel.EmbeddableType}. * Implementation of {@link jakarta.persistence.metamodel.EmbeddableType}.
@ -33,7 +32,7 @@ public class EmbeddableTypeImpl<J>
JavaType<J> javaType, JavaType<J> javaType,
boolean isDynamic, boolean isDynamic,
JpaMetamodelImplementor domainMetamodel) { JpaMetamodelImplementor domainMetamodel) {
super( javaType.getJavaType().getTypeName(), javaType, null, domainMetamodel ); super( javaType.getTypeName(), javaType, null, domainMetamodel );
this.isDynamic = isDynamic; this.isDynamic = isDynamic;
} }

View File

@ -51,7 +51,7 @@ public class MappedSuperclassTypeImpl<J> extends AbstractIdentifiableType<J> imp
IdentifiableDomainType<? super J> superType, IdentifiableDomainType<? super J> superType,
JpaMetamodelImplementor jpaMetamodel) { JpaMetamodelImplementor jpaMetamodel) {
this( this(
javaType.getJavaType().getTypeName(), javaType.getTypeName(),
mappedSuperclass.getDeclaredIdentifierMapper() != null mappedSuperclass.getDeclaredIdentifierMapper() != null
|| superType != null && superType.hasIdClass(), || superType != null && superType.hasIdClass(),
mappedSuperclass.hasIdentifierProperty(), mappedSuperclass.hasIdentifierProperty(),

View File

@ -6087,15 +6087,11 @@ public abstract class AbstractEntityPersister
Locale.ROOT, Locale.ROOT,
"Could not resolve attribute '%s' of '%s' due to the attribute being declared in multiple subtypes '%s' and '%s'", "Could not resolve attribute '%s' of '%s' due to the attribute being declared in multiple subtypes '%s' and '%s'",
name, name,
getJavaType().getJavaType().getTypeName(), getJavaType().getTypeName(),
attribute.asAttributeMapping().getDeclaringType() attribute.asAttributeMapping().getDeclaringType()
.getJavaType() .getJavaType().getTypeName(),
.getJavaType()
.getTypeName(),
subDefinedAttribute.asAttributeMapping().getDeclaringType() subDefinedAttribute.asAttributeMapping().getDeclaringType()
.getJavaType() .getJavaType().getTypeName()
.getJavaType()
.getTypeName()
) )
); );
} }

View File

@ -405,8 +405,8 @@ public class QuerySqmImpl<R>
// throw new SemanticException( // throw new SemanticException(
// String.format( // String.format(
// "Expected insert attribute type [%s] did not match Query selection type [%s] at selection index [%d]", // "Expected insert attribute type [%s] did not match Query selection type [%s] at selection index [%d]",
// insertionTargetPaths.get( i ).getJavaTypeDescriptor().getJavaType().getTypeName(), // insertionTargetPaths.get( i ).getJavaTypeDescriptor().getTypeName(),
// expression.getNodeJavaType().getJavaType().getTypeName(), // expression.getNodeJavaType().getTypeName(),
// i // i
// ), // ),
// hqlString, // hqlString,

View File

@ -117,7 +117,7 @@ public class SqmPolymorphicRootDescriptor<T> implements EntityDomainType<T> {
@Override @Override
public String getName() { public String getName() {
return polymorphicJavaType.getJavaType().getTypeName(); return polymorphicJavaType.getTypeName();
} }
@Override @Override

View File

@ -100,7 +100,7 @@ public class SqmEnumLiteral<E extends Enum<E>> extends SqmLiteral<E> implements
String.format( String.format(
Locale.ROOT, Locale.ROOT,
"Static enum reference [%s#%s] cannot be de-referenced", "Static enum reference [%s#%s] cannot be de-referenced",
referencedEnumTypeDescriptor.getJavaType().getTypeName(), referencedEnumTypeDescriptor.getTypeName(),
enumValueName enumValueName
) )
); );
@ -115,7 +115,7 @@ public class SqmEnumLiteral<E extends Enum<E>> extends SqmLiteral<E> implements
String.format( String.format(
Locale.ROOT, Locale.ROOT,
"Static enum reference [%s#%s] cannot be de-referenced", "Static enum reference [%s#%s] cannot be de-referenced",
referencedEnumTypeDescriptor.getJavaType().getTypeName(), referencedEnumTypeDescriptor.getTypeName(),
enumValueName enumValueName
) )
); );

View File

@ -243,7 +243,7 @@ public class SqmFieldLiteral<T> implements SqmExpression<T>, SqmExpressible<T>,
String.format( String.format(
Locale.ROOT, Locale.ROOT,
"Static field reference [%s#%s] cannot be de-referenced", "Static field reference [%s#%s] cannot be de-referenced",
fieldJavaType.getJavaType().getTypeName(), fieldJavaType.getTypeName(),
fieldName fieldName
) )
); );
@ -258,7 +258,7 @@ public class SqmFieldLiteral<T> implements SqmExpression<T>, SqmExpressible<T>,
String.format( String.format(
Locale.ROOT, Locale.ROOT,
"Static field reference [%s#%s] cannot be de-referenced", "Static field reference [%s#%s] cannot be de-referenced",
fieldJavaType.getJavaType().getTypeName(), fieldJavaType.getTypeName(),
fieldName fieldName
) )
); );

View File

@ -68,7 +68,7 @@ public class BasicResultAssembler<J> implements DomainResultAssembler<J> {
String.format( String.format(
Locale.ROOT, Locale.ROOT,
"Expecting raw JDBC value of type `%s`, but found `%s` : [%s]", "Expecting raw JDBC value of type `%s`, but found `%s` : [%s]",
valueConverter.getRelationalJavaType().getJavaType().getTypeName(), valueConverter.getRelationalJavaType().getTypeName(),
jdbcValue.getClass().getName(), jdbcValue.getClass().getName(),
jdbcValue jdbcValue
) )

View File

@ -90,7 +90,7 @@ public class DynamicInstantiation<T> implements DomainResultProducer {
@Override @Override
public String toString() { public String toString() {
return "DynamicInstantiation(" + getTargetJavaType().getJavaType().getTypeName() + ")"; return "DynamicInstantiation(" + getTargetJavaType().getTypeName() + ")";
} }
@Override @Override

View File

@ -94,7 +94,7 @@ public class DynamicInstantiationAssemblerInjectionImpl<T> implements DomainResu
catch ( NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException catch ( NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException
| java.lang.InstantiationException e ) { | java.lang.InstantiationException e ) {
throw new InstantiationException( "Error instantiating class '" throw new InstantiationException( "Error instantiating class '"
+ target.getJavaType().getTypeName() + "' using default constructor: " + e.getMessage(), e ); + target.getTypeName() + "' using default constructor: " + e.getMessage(), e );
} }
for ( BeanInjection beanInjection : beanInjections ) { for ( BeanInjection beanInjection : beanInjections ) {
final Object assembled = beanInjection.getValueAssembler().assemble( rowProcessingState, options ); final Object assembled = beanInjection.getValueAssembler().assemble( rowProcessingState, options );

View File

@ -180,20 +180,20 @@ public class DynamicInstantiationResultImpl<R> implements DynamicInstantiationRe
if ( log.isDebugEnabled() ) { if ( log.isDebugEnabled() ) {
log.debugf( log.debugf(
"Could not locate appropriate constructor for dynamic instantiation of [%s]; attempting bean-injection instantiation", "Could not locate appropriate constructor for dynamic instantiation of [%s]; attempting bean-injection instantiation",
javaType.getJavaType().getTypeName() javaType.getTypeName()
); );
} }
if ( !areAllArgumentsAliased) { if ( !areAllArgumentsAliased) {
throw new IllegalStateException( throw new IllegalStateException(
"Cannot instantiate class '" + javaType.getJavaType().getTypeName() + "'" "Cannot instantiate class '" + javaType.getTypeName() + "'"
+ " (it has no constructor with signature " + signature() + " (it has no constructor with signature " + signature()
+ ", and not every argument has an alias)" + ", and not every argument has an alias)"
); );
} }
if ( !duplicatedAliases.isEmpty() ) { if ( !duplicatedAliases.isEmpty() ) {
throw new IllegalStateException( throw new IllegalStateException(
"Cannot instantiate class '" + javaType.getJavaType().getTypeName() + "'" "Cannot instantiate class '" + javaType.getTypeName() + "'"
+ " (it has no constructor with signature " + signature() + " (it has no constructor with signature " + signature()
+ ", and has arguments with duplicate aliases [" + ", and has arguments with duplicate aliases ["
+ StringHelper.join( ",", duplicatedAliases) + "])" + StringHelper.join( ",", duplicatedAliases) + "])"
@ -205,7 +205,7 @@ public class DynamicInstantiationResultImpl<R> implements DynamicInstantiationRe
private List<String> signature() { private List<String> signature() {
return argumentResults.stream() return argumentResults.stream()
.map( adt -> adt.getResultJavaType().getJavaType().getTypeName() ) .map( adt -> adt.getResultJavaType().getTypeName() )
.collect( toList() ); .collect( toList() );
} }
} }

View File

@ -119,7 +119,7 @@ public abstract class AbstractStandardBasicType<T>
@Override @Override
public String[] getRegistrationKeys() { public String[] getRegistrationKeys() {
return registerUnderJavaType() return registerUnderJavaType()
? new String[] { getName(), javaType.getJavaType().getTypeName() } ? new String[] { getName(), javaType.getTypeName() }
: new String[] { getName() }; : new String[] { getName() };
} }

View File

@ -217,7 +217,7 @@ public abstract class CollectionType extends AbstractType implements Association
@Override @Override
public String getName() { public String getName() {
return getReturnedClass().getName() + '(' + getRole() + ')'; return getReturnedClassName() + '(' + getRole() + ')';
} }
/** /**

View File

@ -663,7 +663,7 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen
} }
} }
throw new PropertyNotFoundException( throw new PropertyNotFoundException(
"Could not resolve attribute '" + name + "' of '" + getReturnedClass().getName() + "'" "Could not resolve attribute '" + name + "' of '" + getReturnedClassName() + "'"
+ " (must be one of '" + StringHelper.join("', '", names) + "')" + " (must be one of '" + StringHelper.join("', '", names) + "')"
); );
} }

View File

@ -133,7 +133,7 @@ public class SerializableToBlobType<T extends Serializable> implements BasicType
@Override @Override
public String[] getRegistrationKeys() { public String[] getRegistrationKeys() {
return registerUnderJavaType() return registerUnderJavaType()
? new String[] { getName(), javaType.getJavaType().getTypeName() } ? new String[] { getName(), javaType.getTypeName() }
: new String[] { getName() }; : new String[] { getName() };
} }

View File

@ -28,7 +28,7 @@ public class StandardBasicTypeTemplate<J> extends AbstractSingleColumnStandardBa
super( jdbcType, javaType ); super( jdbcType, javaType );
this.registrationKeys = registrationKeys; this.registrationKeys = registrationKeys;
this.name = javaType.getJavaType() == null ? "(map-mode)" : javaType.getJavaType().getTypeName() this.name = javaType.getJavaType() == null ? "(map-mode)" : javaType.getTypeName()
+ " -> " + jdbcType.getDefaultSqlTypeCode(); + " -> " + jdbcType.getDefaultSqlTypeCode();
} }

View File

@ -123,10 +123,21 @@ public interface Type extends Serializable {
/** /**
* The class handled by this type. * The class handled by this type.
* *
* @return The java type class handled by this type. * @return The Java class handled by this type.
*/ */
Class<?> getReturnedClass(); Class<?> getReturnedClass();
/**
* The qualified name of the class handled by this type.
*
* @return The qualified Java class name.
*
* @since 6.5
*/
default String getReturnedClassName() {
return getReturnedClass().getName();
}
/** /**
* Compare two instances of the class mapped by this type for persistence "equality", * Compare two instances of the class mapped by this type for persistence "equality",
* that is, equality of persistent state, taking a shortcut for entity references. * that is, equality of persistent state, taking a shortcut for entity references.

View File

@ -82,6 +82,6 @@ public abstract class AbstractTemporalJavaType<T>
@Override @Override
public String toString() { public String toString() {
return "TemporalJavaType(javaType=" + getJavaType().getTypeName() + ")"; return "TemporalJavaType(javaType=" + getTypeName() + ")";
} }
} }

View File

@ -101,7 +101,7 @@ public class BigDecimalJavaType extends AbstractClassJavaType<BigDecimal> {
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "byte": case "byte":
case "java.lang.Byte": case "java.lang.Byte":
case "short": case "short":

View File

@ -99,7 +99,7 @@ public class BigIntegerJavaType extends AbstractClassJavaType<BigInteger> {
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "byte": case "byte":
case "java.lang.Byte": case "java.lang.Byte":
case "short": case "short":

View File

@ -132,7 +132,7 @@ public class CalendarDateJavaType extends AbstractTemporalJavaType<Calendar> {
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "java.sql.Date": case "java.sql.Date":
return true; return true;
default: default:

View File

@ -149,7 +149,7 @@ public class CalendarJavaType extends AbstractTemporalJavaType<Calendar> impleme
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "java.util.Date": case "java.util.Date":
case "java.sql.Date": case "java.sql.Date":
case "java.sql.Timestamp": case "java.sql.Timestamp":

View File

@ -134,7 +134,7 @@ public class CalendarTimeJavaType extends AbstractTemporalJavaType<Calendar> {
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "java.sql.Time": case "java.sql.Time":
return true; return true;
default: default:

View File

@ -169,7 +169,7 @@ public class DateJavaType extends AbstractTemporalJavaType<Date> implements Vers
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "java.sql.Date": case "java.sql.Date":
case "java.sql.Timestamp": case "java.sql.Timestamp":
case "java.util.Calendar": case "java.util.Calendar":

View File

@ -100,7 +100,7 @@ public class DoubleJavaType extends AbstractClassJavaType<Double> implements
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "byte": case "byte":
case "java.lang.Byte": case "java.lang.Byte":
case "short": case "short":

View File

@ -99,7 +99,7 @@ public class FloatJavaType extends AbstractClassJavaType<Float> implements Primi
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "byte": case "byte":
case "java.lang.Byte": case "java.lang.Byte":
case "short": case "short":

View File

@ -96,7 +96,7 @@ public class IntegerJavaType extends AbstractClassJavaType<Integer>
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "byte": case "byte":
case "java.lang.Byte": case "java.lang.Byte":
case "short": case "short":

View File

@ -194,7 +194,7 @@ public class JdbcTimestampJavaType extends AbstractTemporalJavaType<Date> implem
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "java.sql.Date": case "java.sql.Date":
case "java.sql.Timestamp": case "java.sql.Timestamp":
case "java.util.Date": case "java.util.Date":

View File

@ -163,7 +163,7 @@ public class LocalDateJavaType extends AbstractTemporalJavaType<LocalDate> {
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "java.sql.Date": case "java.sql.Date":
return true; return true;
default: default:

View File

@ -162,7 +162,7 @@ public class LocalDateTimeJavaType extends AbstractTemporalJavaType<LocalDateTim
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "java.sql.Date": case "java.sql.Date":
case "java.sql.Timestamp": case "java.sql.Timestamp":
case "java.util.Date": case "java.util.Date":

View File

@ -169,7 +169,7 @@ public class LocalTimeJavaType extends AbstractTemporalJavaType<LocalTime> {
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "java.sql.Time": case "java.sql.Time":
return true; return true;
default: default:

View File

@ -96,7 +96,7 @@ public class LongJavaType extends AbstractClassJavaType<Long>
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "byte": case "byte":
case "java.lang.Byte": case "java.lang.Byte":
case "short": case "short":

View File

@ -42,7 +42,7 @@ public class ShortJavaType extends AbstractClassJavaType<Short>
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "byte": case "byte":
case "java.lang.Byte": case "java.lang.Byte":
return true; return true;

View File

@ -119,7 +119,7 @@ public class StringJavaType extends AbstractClassJavaType<String> {
@Override @Override
public boolean isWider(JavaType<?> javaType) { public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) { switch ( javaType.getTypeName() ) {
case "char": case "char":
case "char[]": case "char[]":
case "java.lang.Character": case "java.lang.Character":

View File

@ -42,7 +42,7 @@ public class EmbeddableAggregateJavaType<T> extends AbstractClassJavaType<T> {
return descriptor; return descriptor;
} }
throw new JdbcTypeRecommendationException( throw new JdbcTypeRecommendationException(
"Could not determine recommended JdbcType for `" + getJavaType().getTypeName() + "`" "Could not determine recommended JdbcType for `" + getTypeName() + "`"
); );
} }
@ -54,7 +54,7 @@ public class EmbeddableAggregateJavaType<T> extends AbstractClassJavaType<T> {
@Override @Override
public T fromString(CharSequence string) { public T fromString(CharSequence string) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Conversion from String strategy not known for this Java type : " + getJavaType().getTypeName() "Conversion from String strategy not known for this Java type: " + getTypeName()
); );
} }
@ -65,7 +65,7 @@ public class EmbeddableAggregateJavaType<T> extends AbstractClassJavaType<T> {
return (X) value; return (X) value;
} }
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Unwrap strategy not known for this Java type : " + getJavaType().getTypeName() "Unwrap strategy not known for this Java type: " + getTypeName()
); );
} }
@ -76,12 +76,12 @@ public class EmbeddableAggregateJavaType<T> extends AbstractClassJavaType<T> {
return (T) value; return (T) value;
} }
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Wrap strategy not known for this Java type : " + getJavaType().getTypeName() "Wrap strategy not known for this Java type: " + getTypeName()
); );
} }
@Override @Override
public String toString() { public String toString() {
return "BasicJavaType(" + getJavaType().getTypeName() + ")"; return "BasicJavaType(" + getTypeName() + ")";
} }
} }

View File

@ -30,7 +30,7 @@ public class EntityJavaType<T> extends AbstractClassJavaType<T> {
@Override @Override
public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) { public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) {
throw new JdbcTypeRecommendationException( throw new JdbcTypeRecommendationException(
"Could not determine recommended JdbcType for `" + getJavaType().getTypeName() + "`" "Could not determine recommended JdbcType for '" + getTypeName() + "'"
); );
} }
@ -65,26 +65,26 @@ public class EntityJavaType<T> extends AbstractClassJavaType<T> {
@Override @Override
public T fromString(CharSequence string) { public T fromString(CharSequence string) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Conversion from String strategy not known for this Java type : " + getJavaType().getTypeName() "Conversion from String strategy not known for this Java type: " + getTypeName()
); );
} }
@Override @Override
public <X> X unwrap(T value, Class<X> type, WrapperOptions options) { public <X> X unwrap(T value, Class<X> type, WrapperOptions options) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Unwrap strategy not known for this Java type : " + getJavaType().getTypeName() "Unwrap strategy not known for this Java type: " + getTypeName()
); );
} }
@Override @Override
public <X> T wrap(X value, WrapperOptions options) { public <X> T wrap(X value, WrapperOptions options) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Wrap strategy not known for this Java type : " + getJavaType().getTypeName() "Wrap strategy not known for this Java type: " + getTypeName()
); );
} }
@Override @Override
public String toString() { public String toString() {
return "EntityJavaType(" + getJavaType().getTypeName() + ")"; return "EntityJavaType(" + getTypeName() + ")";
} }
} }

View File

@ -43,7 +43,7 @@ public abstract class FormatMapperBasedJavaType<T> extends AbstractJavaType<T> i
@Override @Override
public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) { public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) {
throw new JdbcTypeRecommendationException( throw new JdbcTypeRecommendationException(
"Could not determine recommended JdbcType for Java type '" + getJavaType().getTypeName() + "'" "Could not determine recommended JdbcType for Java type '" + getTypeName() + "'"
); );
} }
@ -76,7 +76,7 @@ public abstract class FormatMapperBasedJavaType<T> extends AbstractJavaType<T> i
return (X) getFormatMapper( typeConfiguration ).toString( value, this, options ); return (X) getFormatMapper( typeConfiguration ).toString( value, this, options );
} }
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Unwrap strategy not known for this Java type : " + getJavaType().getTypeName() "Unwrap strategy not known for this Java type: " + getTypeName()
); );
} }
@ -90,7 +90,7 @@ public abstract class FormatMapperBasedJavaType<T> extends AbstractJavaType<T> i
return getFormatMapper( typeConfiguration ).fromString( (String) value, this, options ); return getFormatMapper( typeConfiguration ).fromString( (String) value, this, options );
} }
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Wrap strategy not known for this Java type : " + getJavaType().getTypeName() "Wrap strategy not known for this Java type: " + getTypeName()
); );
} }

View File

@ -30,7 +30,7 @@ public class JavaTypeBasicAdaptor<T> extends AbstractClassJavaType<T> {
@Override @Override
public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) { public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) {
throw new JdbcTypeRecommendationException( throw new JdbcTypeRecommendationException(
"Could not determine recommended JdbcType for `" + getJavaType().getTypeName() + "`" "Could not determine recommended JdbcType for '" + getTypeName() + "'"
); );
} }
@ -42,26 +42,26 @@ public class JavaTypeBasicAdaptor<T> extends AbstractClassJavaType<T> {
@Override @Override
public T fromString(CharSequence string) { public T fromString(CharSequence string) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Conversion from String strategy not known for this Java type : " + getJavaType().getTypeName() "Conversion from String strategy not known for this Java type: " + getTypeName()
); );
} }
@Override @Override
public <X> X unwrap(T value, Class<X> type, WrapperOptions options) { public <X> X unwrap(T value, Class<X> type, WrapperOptions options) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Unwrap strategy not known for this Java type : " + getJavaType().getTypeName() "Unwrap strategy not known for this Java type: " + getTypeName()
); );
} }
@Override @Override
public <X> T wrap(X value, WrapperOptions options) { public <X> T wrap(X value, WrapperOptions options) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Wrap strategy not known for this Java type : " + getJavaType().getTypeName() "Wrap strategy not known for this Java type: " + getTypeName()
); );
} }
@Override @Override
public String toString() { public String toString() {
return "JavaTypeBasicAdaptor(" + getJavaType().getTypeName() + ")"; return "JavaTypeBasicAdaptor(" + getTypeName() + ")";
} }
} }

View File

@ -38,6 +38,6 @@ public class JsonJavaType<T> extends FormatMapperBasedJavaType<T> {
@Override @Override
public String toString() { public String toString() {
return "JsonJavaType(" + getJavaType().getTypeName() + ")"; return "JsonJavaType(" + getTypeName() + ")";
} }
} }

View File

@ -19,22 +19,35 @@ import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
* {@link org.hibernate.type.descriptor.java.JavaType} for a given Java type. * {@link org.hibernate.type.descriptor.java.JavaType} for a given Java type.
*/ */
public final class UnknownBasicJavaType<T> extends AbstractJavaType<T> { public final class UnknownBasicJavaType<T> extends AbstractJavaType<T> {
private final String typeName;
public UnknownBasicJavaType(Class<T> type) { public UnknownBasicJavaType(Class<T> type) {
this( type, type.getTypeName() );
}
public UnknownBasicJavaType(Class<T> type, String typeName) {
super( type ); super( type );
this.typeName = typeName;
} }
public UnknownBasicJavaType(Class<T> type, MutabilityPlan<T> mutabilityPlan) { public UnknownBasicJavaType(Class<T> type, MutabilityPlan<T> mutabilityPlan) {
super( type, mutabilityPlan ); super( type, mutabilityPlan );
this.typeName = type.getTypeName();
} }
public UnknownBasicJavaType(Type type, MutabilityPlan<T> mutabilityPlan) { public UnknownBasicJavaType(Type type, MutabilityPlan<T> mutabilityPlan) {
super( type, mutabilityPlan ); super( type, mutabilityPlan );
this.typeName = type.getTypeName();
}
@Override
public String getTypeName() {
return typeName;
} }
@Override @Override
public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) { public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) {
throw new JdbcTypeRecommendationException( throw new JdbcTypeRecommendationException(
"Could not determine recommended JdbcType for Java type '" + getJavaType().getTypeName() + "'" "Could not determine recommended JdbcType for Java type '" + getTypeName() + "'"
); );
} }
@ -46,7 +59,7 @@ public final class UnknownBasicJavaType<T> extends AbstractJavaType<T> {
@Override @Override
public T fromString(CharSequence string) { public T fromString(CharSequence string) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Conversion from String strategy not known for this Java type : " + getJavaType().getTypeName() "Conversion from String strategy not known for this Java type: " + getTypeName()
); );
} }
@ -57,7 +70,7 @@ public final class UnknownBasicJavaType<T> extends AbstractJavaType<T> {
return (X) value; return (X) value;
} }
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Unwrap strategy not known for this Java type : " + getJavaType().getTypeName() "Unwrap strategy not known for this Java type: " + getTypeName()
); );
} }
@ -68,12 +81,12 @@ public final class UnknownBasicJavaType<T> extends AbstractJavaType<T> {
return (T) value; return (T) value;
} }
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Wrap strategy not known for this Java type : " + getJavaType().getTypeName() "Wrap strategy not known for this Java type: " + getTypeName()
); );
} }
@Override @Override
public String toString() { public String toString() {
return "BasicJavaType(" + getJavaType().getTypeName() + ")"; return "BasicJavaType(" + getTypeName() + ")";
} }
} }

View File

@ -38,6 +38,6 @@ public class XmlJavaType<T> extends FormatMapperBasedJavaType<T> {
@Override @Override
public String toString() { public String toString() {
return "XmlJavaType(" + getJavaType().getTypeName() + ")"; return "XmlJavaType(" + getTypeName() + ")";
} }
} }

View File

@ -1061,16 +1061,15 @@ public abstract class MockSessionFactory
} }
} }
private EmbeddableTypeImpl<Object> createEmbeddableDomainType(String entityName, CompositeType compositeType, ManagedDomainType<?> owner) { private EmbeddableTypeImpl<?> createEmbeddableDomainType(String entityName, CompositeType compositeType, ManagedDomainType<?> owner) {
return new EmbeddableTypeImpl<Object>(new UnknownBasicJavaType<>(Object.class), true, metamodel.getJpaMetamodel()) { final JavaType<Object> javaType = new UnknownBasicJavaType<>(Object.class, compositeType.getReturnedClassName());
return new EmbeddableTypeImpl<>(javaType, true, metamodel.getJpaMetamodel()) {
@Override @Override
public PersistentAttribute<Object, Object> findAttribute(String name) { public PersistentAttribute<Object, Object> findAttribute(String name) {
int i = compositeType.getPropertyIndex(name);
Type subtype = compositeType.getSubtypes()[i];
return createAttribute( return createAttribute(
name, name,
entityName, //TOOD: WRONG!!! entityName,
subtype, compositeType.getSubtypes()[compositeType.getPropertyIndex(name)],
owner owner
); );
} }

View File

@ -264,6 +264,11 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory {
return type.getSimpleName().toString(); return type.getSimpleName().toString();
} }
@Override
public String getReturnedClassName() {
return type.getQualifiedName().toString();
}
@Override @Override
public boolean isComponentType() { public boolean isComponentType() {
return true; return true;
@ -803,11 +808,10 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory {
// } // }
else if (type instanceof BasicType) { else if (type instanceof BasicType) {
String className; String className;
//sadly there is no way to get the classname //TODO: custom impl of getReturnedClassName()
//from a Hibernate Type without trying to load // for many more Hibernate types!
//the class!
try { try {
className = type.getReturnedClass().getName(); className = type.getReturnedClassName();
} }
catch (Exception e) { catch (Exception e) {
continue; continue;

View File

@ -0,0 +1,55 @@
package org.hibernate.jpamodelgen.test.hqlsql;
import jakarta.persistence.Embeddable;
import java.util.Objects;
@Embeddable
public final class Address {
private String street;
private String city;
private String zip;
public Address(String street, String city, String zip) {
this.street = street;
this.city = city;
this.zip = zip;
}
Address() {}
public String street() {
return street;
}
public String city() {
return city;
}
public String zip() {
return zip;
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (Address) obj;
return Objects.equals(this.street, that.street) &&
Objects.equals(this.city, that.city) &&
Objects.equals(this.zip, that.zip);
}
@Override
public int hashCode() {
return Objects.hash(street, city, zip);
}
@Override
public String toString() {
return "Address[" +
"street=" + street + ", " +
"city=" + city + ", " +
"zip=" + zip + ']';
}
}

View File

@ -6,6 +6,7 @@ import jakarta.persistence.ManyToOne;
import org.hibernate.annotations.NaturalId; import org.hibernate.annotations.NaturalId;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate;
@Entity @Entity
public class Book { public class Book {
@ -16,4 +17,5 @@ public class Book {
@ManyToOne Publisher publisher; @ManyToOne Publisher publisher;
BigDecimal price; BigDecimal price;
int pages; int pages;
LocalDate publicationDate;
} }

View File

@ -40,6 +40,9 @@ public interface Dao {
@HQL("from Book where isbn = :isbn") @HQL("from Book where isbn = :isbn")
Book findByIsbn(String isbn); Book findByIsbn(String isbn);
@HQL("order by isbn asc, publicationDate desc")
List<Book> allBooks();
@SQL("select * from Book where isbn = :isbn") @SQL("select * from Book where isbn = :isbn")
Book findByIsbnNative(String isbn); Book findByIsbnNative(String isbn);
@ -64,4 +67,6 @@ public interface Dao {
@HQL("select new list(title, pages) from Book") @HQL("select new list(title, pages) from Book")
List<List> dtoQuery4(); List<List> dtoQuery4();
@HQL("from Publisher where address = :address")
List<Publisher> publisherAt(Address address);
} }

View File

@ -7,4 +7,5 @@ import jakarta.persistence.Id;
public class Publisher { public class Publisher {
@Id Long id; @Id Long id;
String name; String name;
Address address;
} }