We're updating the issue view to help you get more done. 

Hibernate Tools StandardTableExporter does not add a dot (".") between table and column names, when generating comment DDL

Description

Currently the generator outputs comments like this:

1 comment on column T_JES_COMMANDATTEMPTS is 'Type:Integer,Anzahl der Retries';

Notice the missing dot / point to separate the table name (T_JES_COMMAND) and the column name (ATTEMPTS).

The problem can be fixed by overriding the applyComments method of the StandardTableExporter class as follows:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 public class MobiOracle10gDialect extends Oracle10gDialect { @Override public boolean supportsUniqueConstraintInCreateAlterTable() { return false; } @Override public Exporter<Table> getTableExporter() { return new StandardTableExporter(this){ protected void applyComments(Table table, QualifiedName tableName, List<String> sqlStrings) { if ( dialect.supportsCommentOn() ) { if ( table.getComment() != null ) { sqlStrings.add( "comment on table " + tableName + " is '" + table.getComment() + "'" ); } final Iterator iter = table.getColumnIterator(); while ( iter.hasNext() ) { Column column = (Column) iter.next(); String columnComment = column.getComment(); if ( columnComment != null ) { //this line is buggy in hibernate 5 :-( //the point is missing between table name and column! sqlStrings.add( "comment on column " + tableName + "." + column.getQuotedName( dialect ) + " is '" + columnComment + "'" ); } } } } }; } }

Compare this line:

1 sqlStrings.add( "comment on column " + tableName + "." + column.getQuotedName( dialect ) + " is '" + columnComment + "'" );

with the original:

1 sqlStrings.add( "comment on column " + tableName + column.getQuotedName( dialect ) + " is '" + columnComment + "'" );

Notice the missing dot.

The following JUnit test demonstrates the problem:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 package ch.mobi.jes.persistence.hibernate.dialect; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.sql.Types; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.relational.Database; import org.hibernate.dialect.Oracle10gDialect; import org.hibernate.engine.jdbc.env.internal.QualifiedObjectNameFormatterStandardImpl; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; import org.junit.jupiter.api.Test; class Oracle10gDialectTest { @Test public void testCommentsAreGeneratedWithDot() { //setup Table table = new Table(); table.setName("MyTable"); table.setQuoted(false); table.setSchema("MySchema"); table.setQuoted(false); Column col = new Column("MyCol"); col.setComment("aComment"); col.setSqlTypeCode(Types.NUMERIC); col.setSqlType("NUM"); table.addColumn(col); Metadata metadata = mock(Metadata.class); Database db = mock(Database.class); when(metadata.getDatabase()).thenReturn(db); JdbcEnvironment env = mock(JdbcEnvironment.class); when(db.getJdbcEnvironment()).thenReturn(env); when(env.getQualifiedObjectNameFormatter()).thenReturn(new QualifiedObjectNameFormatterStandardImpl(NameQualifierSupport.BOTH)); //run String[] sql = new Oracle10gDialect().getTableExporter().getSqlCreateStrings(table, metadata); //assert assertEquals(2, sql.length); assertEquals("create table MySchema.MyTable (MyCol NUM)", sql[0]); //this test fails on the following line, because currently no dot is generated between the table and column name here: // | // v assertEquals("comment on column MySchema.MyTable.MyCol is 'aComment'", sql[1]); } }

Environment

None

Status

Assignee

Andrea Boriero

Reporter

Ant Kutschera

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

4.2.18

Components

Affects versions

5.0.12

Priority

Major