|
1 | 1 | package org.hibernate.orm.test.schemaupdate;
|
2 | 2 |
|
3 |
| -import java.sql.Types; |
4 |
| -import java.util.List; |
5 | 3 | import java.util.Map;
|
6 | 4 |
|
7 |
| -import org.hibernate.Session; |
8 |
| -import org.hibernate.jpa.boot.spi.Bootstrap; |
| 5 | +import org.hibernate.mapping.PersistentClass; |
9 | 6 |
|
10 |
| -import org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter; |
| 7 | +import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; |
11 | 8 | import org.hibernate.testing.orm.junit.JiraKey;
|
12 |
| -import org.junit.jupiter.api.Test; |
13 | 9 |
|
14 | 10 | import jakarta.persistence.Column;
|
15 | 11 | import jakarta.persistence.DiscriminatorColumn;
|
|
21 | 17 |
|
22 | 18 | import static jakarta.persistence.DiscriminatorType.CHAR;
|
23 | 19 | import static jakarta.persistence.InheritanceType.SINGLE_TABLE;
|
24 |
| -import static org.hibernate.cfg.AvailableSettings.HBM2DDL_AUTO; |
25 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
26 |
| -import static org.junit.jupiter.api.Assertions.fail; |
27 | 21 |
|
28 | 22 | @JiraKey("HHH-16551")
|
29 |
| -public class CreateCharDiscriminatorTest { |
| 23 | +public class CreateCharDiscriminatorTest extends BaseNonConfigCoreFunctionalTestCase { |
30 | 24 |
|
31 |
| - @Test |
| 25 | + @org.junit.Test |
32 | 26 | @JiraKey("HHH-16551")
|
33 | 27 | public void testCreateDiscriminatorCharColumnSize() {
|
34 |
| - final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() { |
35 |
| - @Override |
36 |
| - public List<String> getManagedClassNames() { |
37 |
| - return List.of( Parent.class.getName() ); |
38 |
| - } |
39 |
| - }; |
| 28 | + PersistentClass classMapping = metadata().getEntityBinding( Parent.class.getName() ); |
| 29 | + final var discriminatorColumn = classMapping.getDiscriminator().getColumns().get( 0 ); |
| 30 | + assertEquals( discriminatorColumn.getLength(), 1L ); |
| 31 | + } |
40 | 32 |
|
| 33 | + @Override |
| 34 | + protected void addSettings(Map<String, Object> settings) { |
| 35 | + settings.put( "jakarta.persistence.validation.mode", "ddl" ); |
| 36 | + } |
41 | 37 |
|
42 |
| - final var settings = Map.of( HBM2DDL_AUTO, "create-drop" ); |
43 |
| - |
44 |
| - try (var factory = Bootstrap.getEntityManagerFactoryBuilder( pu, settings ).build(); |
45 |
| - var manager = factory.createEntityManager()) { |
46 |
| - manager.unwrap( Session.class ).doWork( conn -> { |
47 |
| - try (var rs = conn.getMetaData().getColumns( null, null, null, null )) { |
48 |
| - if ( rs.next() ) { |
49 |
| - do { |
50 |
| - if ( "parent".equalsIgnoreCase( rs.getString( "TABLE_NAME" ) ) && |
51 |
| - "discr".equalsIgnoreCase( rs.getString( "COLUMN_NAME" ) ) ) { |
52 |
| - assertEquals( Types.CHAR, rs.getInt( "DATA_TYPE" ) ); |
53 |
| - assertEquals( 1, rs.getInt( "COLUMN_SIZE" ) ); |
54 |
| - } |
55 |
| - } while ( rs.next() ); |
56 |
| - } |
57 |
| - else { |
58 |
| - fail( "Table and/or columns has not been created, why?!?" ); |
59 |
| - } |
60 |
| - } |
61 |
| - } ); |
62 |
| - } |
| 38 | + @Override |
| 39 | + protected Class<?>[] getAnnotatedClasses() { |
| 40 | + return new Class<?>[] { |
| 41 | + Parent.class |
| 42 | + }; |
63 | 43 | }
|
64 | 44 |
|
65 | 45 | @Entity
|
66 | 46 | @Table(name = "parent")
|
67 | 47 | @Inheritance(strategy = SINGLE_TABLE)
|
68 |
| - @DiscriminatorColumn(name = "discr", discriminatorType = CHAR) |
| 48 | + @DiscriminatorColumn(name = "discr", discriminatorType = CHAR, length = 2) |
69 | 49 | @DiscriminatorValue("*")
|
70 | 50 | public static class Parent {
|
71 | 51 |
|
|
0 commit comments