Skip to content

HHH-19389 proper error when @Struct is used on Dialect with no support for UDTs #10086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ public void doSecondPass(Map<String, PersistentClass> persistentClasses) throws
structName.getCatalogName(),
structName.getSchemaName()
);
final UserDefinedObjectType udt = new UserDefinedObjectType( "orm", namespace, structName.getObjectName() );
if ( !database.getDialect().supportsUserDefinedTypes() ) {
throw new MappingException( "Database does not support user-defined types (remove '@Struct' annotation)" );
}
final UserDefinedObjectType udt =
new UserDefinedObjectType( "orm", namespace, structName.getObjectName() );
final Comment comment = componentClassDetails.getDirectAnnotationUsage( Comment.class );
if ( comment != null ) {
udt.setComment( comment.value() );
Expand Down Expand Up @@ -231,17 +235,15 @@ else if ( value instanceof Collection collection ) {
}

private boolean isAggregateArray() {
switch ( component.getAggregateColumn().getSqlTypeCode( context.getMetadataCollector() ) ) {
case SqlTypes.STRUCT_ARRAY:
case SqlTypes.STRUCT_TABLE:
case SqlTypes.JSON_ARRAY:
case SqlTypes.XML_ARRAY:
case SqlTypes.ARRAY:
case SqlTypes.TABLE:
return true;
default:
return false;
}
return switch ( component.getAggregateColumn().getSqlTypeCode( context.getMetadataCollector() ) ) {
case SqlTypes.STRUCT_ARRAY,
SqlTypes.STRUCT_TABLE,
SqlTypes.JSON_ARRAY,
SqlTypes.XML_ARRAY,
SqlTypes.ARRAY,
SqlTypes.TABLE -> true;
default -> false;
};
}

private void orderColumns(UserDefinedObjectType userDefinedType, int[] originalOrder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ public int getDefaultDecimalPrecision() {
return 31;
}

@Override
public boolean supportsUserDefinedTypes() {
return true;
}

@Override
protected boolean supportsPredicateAsExpression() {
return getDB2Version().isSameOrAfter( 11 );
Expand Down
11 changes: 11 additions & 0 deletions hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -4506,6 +4506,17 @@ public AggregateSupport getAggregateSupport() {
return AggregateSupportImpl.INSTANCE;
}

/**
* Does the database support user defined types?
*
* @see org.hibernate.annotations.Struct
*
* @since 7.1
*/
public boolean supportsUserDefinedTypes() {
return false;
}

/**
* Does this database have native support for ANSI SQL standard arrays which
* are expressed in terms of the element type name: {@code integer array}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,11 @@ public boolean supportsBitType() {
return false;
}

@Override
public boolean supportsUserDefinedTypes() {
return true;
}

@Override
public String getArrayTypeName(String javaElementTypeName, String elementTypeName, Integer maxLength) {
return ( javaElementTypeName == null ? elementTypeName : javaElementTypeName ) + "Array";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,11 @@ public int getMaxIdentifierLength() {
return 63;
}

@Override
public boolean supportsUserDefinedTypes() {
return true;
}

@Override
public boolean supportsStandardArrays() {
return true;
Expand Down