1

After changing database schema in wildfly app server, hibernate retrieves existed tables from older datasource but new tables are created in my new datasource.

I debbuged some hibernate source codes. Noticed in org.hibernate.tool.hbm2ddl.TableMetadata class constructor parameters shows not consistent behaviour.

TableMetadata(ResultSet rs, DatabaseMetaData meta, boolean extras) throws SQLException {
    this.catalog = rs.getString("TABLE_CAT");
    this.schema = rs.getString("TABLE_SCHEM");
    this.name = rs.getString("TABLE_NAME");
    this.initColumns(meta);
    if(extras) {
        this.initForeignKeys(meta);
        this.initIndexes(meta);
    }

    String cat = this.catalog == null?"":this.catalog + '.';
    String schem = this.schema == null?"":this.schema + '.';
    LOG.tableFound(cat + schem + this.name);
    LOG.columns(this.columns.keySet());
    if(extras) {
        LOG.foreignKeys(this.foreignKeys.keySet());
        LOG.indexes(this.indexes.keySet());
    }

}

why rs.getString("TABLE_SCHEM") and meta.getConnection.getSchema() are giving different table schemas.
and how hibernate can access my older schema without username and password infos?

how could it be possible ?

yfpayalan
  • 33
  • 1
  • 9
  • Of course they can return different things. `Connection.getSchema()` returns the *current* schema of the connection. `TABLE_SCHEM` is the schema in which the table was created. Those could be two completely different things. Also: which DBMS are you using? –  Jul 12 '16 at 11:09
  • Oracle Database 12c, version 12.1.0.2.0 – yfpayalan Jul 12 '16 at 11:22
  • In Oracle `getSchema()` returns the current username (unless the current schema was changed with `alter session`). By default Oracle will let a user _list_ tables from other users (e.g. through `DatabaseMetadata.getTables()`) but you wouldn't be able to _access_ them. –  Jul 12 '16 at 11:30
  • as your said my database lets my username list tables from others . for the solution, fixed the problem from persistence level. i have setted **hibernate.default_schema** property in my persistence.xml [http://stackoverflow.com/questions/2737420/how-to-set-up-default-schema-name-in-jpa-configuration](http://stackoverflow.com/questions/2737420/how-to-set-up-default-schema-name-in-jpa-configuration) – yfpayalan Jul 14 '16 at 09:06

0 Answers0