Fix mssql LobSchemaUpdateTest failure

This commit is contained in:
Andrea Boriero 2024-04-11 18:31:24 +02:00 committed by Gavin King
parent 04d22686bb
commit f27dc7d3a8
2 changed files with 29 additions and 6 deletions

View File

@ -38,6 +38,7 @@ import org.hibernate.dialect.sequence.SQLServerSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.dialect.unique.AlterTableUniqueIndexDelegate;
import org.hibernate.dialect.unique.UniqueDelegate;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
@ -72,6 +73,7 @@ import org.hibernate.tool.schema.spi.Exporter;
import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.TimestampUtcAsJdbcTimestampJdbcType;
@ -134,6 +136,25 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
private final StandardSequenceExporter exporter;
private final UniqueDelegate uniqueDelegate = new AlterTableUniqueIndexDelegate(this);
private final SizeStrategy sizeStrategy = new SizeStrategyImpl() {
@Override
public Size resolveSize(
JdbcType jdbcType,
JavaType<?> javaType,
Integer precision,
Integer scale,
Long length) {
switch ( jdbcType.getDdlTypeCode() ) {
case BLOB:
case CLOB:
case NCLOB:
return Size.length( getDefaultLobLength() );
default:
return super.resolveSize( jdbcType, javaType, precision, scale, length );
}
}
};
public SQLServerDialect() {
this( MINIMUM_VERSION );
}
@ -429,6 +450,11 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
};
}
@Override
public SizeStrategy getSizeStrategy() {
return sizeStrategy;
}
@Override
public String castPattern(CastType from, CastType to) {
if ( to == CastType.STRING ) {

View File

@ -3,9 +3,9 @@ package org.hibernate.orm.test.schemaupdate;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.util.EnumSet;
import org.hibernate.annotations.Nationalized;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
@ -14,21 +14,16 @@ import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.hibernate.tool.schema.TargetType;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.util.ServiceRegistryUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@ -120,6 +115,8 @@ public class LobSchemaUpdateTest {
@Lob
protected byte[] blobField;
String name;
public TestEntity() {}
}