diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/CreateCharDiscriminatorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/CreateCharDiscriminatorTest.java index 41acbcde25..602b3c486f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/CreateCharDiscriminatorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/CreateCharDiscriminatorTest.java @@ -1,15 +1,11 @@ package org.hibernate.orm.test.schemaupdate; -import java.sql.Types; -import java.util.List; import java.util.Map; -import org.hibernate.Session; -import org.hibernate.jpa.boot.spi.Bootstrap; +import org.hibernate.mapping.PersistentClass; -import org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter; +import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey; -import org.junit.jupiter.api.Test; import jakarta.persistence.Column; import jakarta.persistence.DiscriminatorColumn; @@ -21,51 +17,35 @@ import jakarta.persistence.Table; import static jakarta.persistence.DiscriminatorType.CHAR; import static jakarta.persistence.InheritanceType.SINGLE_TABLE; -import static org.hibernate.cfg.AvailableSettings.HBM2DDL_AUTO; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; @JiraKey("HHH-16551") -public class CreateCharDiscriminatorTest { +public class CreateCharDiscriminatorTest extends BaseNonConfigCoreFunctionalTestCase { - @Test + @org.junit.Test @JiraKey("HHH-16551") public void testCreateDiscriminatorCharColumnSize() { - final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() { - @Override - public List getManagedClassNames() { - return List.of( Parent.class.getName() ); - } + PersistentClass classMapping = metadata().getEntityBinding( Parent.class.getName() ); + final var discriminatorColumn = classMapping.getDiscriminator().getColumns().get( 0 ); + assertEquals( discriminatorColumn.getLength(), 1L ); + } + + @Override + protected void addSettings(Map settings) { + settings.put( "jakarta.persistence.validation.mode", "ddl" ); + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + Parent.class }; - - - final var settings = Map.of( HBM2DDL_AUTO, "create-drop" ); - - try (var factory = Bootstrap.getEntityManagerFactoryBuilder( pu, settings ).build(); - var manager = factory.createEntityManager()) { - manager.unwrap( Session.class ).doWork( conn -> { - try (var rs = conn.getMetaData().getColumns( null, null, null, null )) { - if ( rs.next() ) { - do { - if ( "parent".equalsIgnoreCase( rs.getString( "TABLE_NAME" ) ) && - "discr".equalsIgnoreCase( rs.getString( "COLUMN_NAME" ) ) ) { - assertEquals( Types.CHAR, rs.getInt( "DATA_TYPE" ) ); - assertEquals( 1, rs.getInt( "COLUMN_SIZE" ) ); - } - } while ( rs.next() ); - } - else { - fail( "Table and/or columns has not been created, why?!?" ); - } - } - } ); - } } @Entity @Table(name = "parent") @Inheritance(strategy = SINGLE_TABLE) - @DiscriminatorColumn(name = "discr", discriminatorType = CHAR) + @DiscriminatorColumn(name = "discr", discriminatorType = CHAR, length = 2) @DiscriminatorValue("*") public static class Parent {