Currently the generator outputs comments like this:
{code} comment on column T_JES_COMMANDATTEMPTS is 'Type:Integer,Anzahl der Retries'; {code}
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:
{code} 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 + "'" ); } } } } }; } } {code}
Compare this line:
{code} sqlStrings.add( "comment on column " + tableName + "." + column.getQuotedName( dialect ) + " is '" + columnComment + "'" ); {code}
with the original:
{code} sqlStrings.add( "comment on column " + tableName + column.getQuotedName( dialect ) + " is '" + columnComment + "'" ); {code}
Notice the missing dot.
The following JUnit tests test demonstrates the problem:
{code} 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]); } } {code} |
|