HHH-17097 Add test for issue
This commit is contained in:
parent
93629f0d2a
commit
eaa94b1305
|
@ -0,0 +1,102 @@
|
||||||
|
package org.hibernate.orm.test.schemaupdate;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
import org.hibernate.dialect.MySQLDialect;
|
||||||
|
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
|
import org.hibernate.tool.schema.TargetType;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||||
|
import org.hibernate.testing.orm.junit.Jira;
|
||||||
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
|
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.Id;
|
||||||
|
import jakarta.persistence.Lob;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
|
|
||||||
|
@Jira("HHH-17097")
|
||||||
|
@BaseUnitTest
|
||||||
|
@RequiresDialect(MySQLDialect.class)
|
||||||
|
public class MySQLLobSchemaCreationTest {
|
||||||
|
private File output;
|
||||||
|
private StandardServiceRegistry ssr;
|
||||||
|
private MetadataImplementor metadata;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
output = File.createTempFile( "update_script", ".sql" );
|
||||||
|
output.deleteOnExit();
|
||||||
|
ssr = ServiceRegistryUtil.serviceRegistry();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearsDown() {
|
||||||
|
output.delete();
|
||||||
|
dropSchema( TestEntity.class );
|
||||||
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSchemaCreation() throws Exception {
|
||||||
|
createSchema( TestEntity.class );
|
||||||
|
String fileContent = new String( Files.readAllBytes( output.toPath() ) ).toLowerCase()
|
||||||
|
.replace( System.lineSeparator(), "" );
|
||||||
|
assertThat( fileContent ).contains( "lobfield longtext" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createSchema(Class... annotatedClasses) {
|
||||||
|
final MetadataSources metadataSources = new MetadataSources( ssr );
|
||||||
|
|
||||||
|
for ( Class c : annotatedClasses ) {
|
||||||
|
metadataSources.addAnnotatedClass( c );
|
||||||
|
}
|
||||||
|
metadata = (MetadataImplementor) metadataSources.buildMetadata();
|
||||||
|
metadata.orderColumns( false );
|
||||||
|
metadata.validate();
|
||||||
|
new SchemaExport()
|
||||||
|
.setHaltOnError( true )
|
||||||
|
.setOutputFile( output.getAbsolutePath() )
|
||||||
|
.setFormat( false )
|
||||||
|
.create( EnumSet.of( TargetType.SCRIPT, TargetType.DATABASE ), metadata );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dropSchema(Class... annotatedClasses) {
|
||||||
|
final MetadataSources metadataSources = new MetadataSources( ssr );
|
||||||
|
|
||||||
|
for ( Class c : annotatedClasses ) {
|
||||||
|
metadataSources.addAnnotatedClass( c );
|
||||||
|
}
|
||||||
|
metadata = (MetadataImplementor) metadataSources.buildMetadata();
|
||||||
|
metadata.orderColumns( false );
|
||||||
|
metadata.validate();
|
||||||
|
new SchemaExport()
|
||||||
|
.setHaltOnError( false )
|
||||||
|
.setFormat( false )
|
||||||
|
.drop( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "TestEntity")
|
||||||
|
public static class TestEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
@Lob
|
||||||
|
private String lobField;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue