org.dbunit.dataset.DataSetException: org.h2.jdbc.JdbcSQLException: Column "NAME" not found; SQL statement:
select NAME, ADMIN, REMARKS, ID, ID, VERSION, FIRST_NAME, IS_ACTIVE, LAST_NAME, LOGIN, PERMISSION_ID from USERS order by ID [42122-147]
String schemaName = _connection.getSchema();
Connection jdbcConnection = _connection.getConnection();
DatabaseMetaData databaseMetaData = jdbcConnection.getMetaData();
ResultSet resultSet = databaseMetaData.getColumns(null, schemaName, tableName, "%");
I don't know DbUnit, maybe you should ask there. Basically,
_connection.getSchema() needs to return "PUBLIC" and not null. Maybe
setting System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_SCHEMA,
"PUBLIC") will help - I found that here:
http://www.dbunit.org/howto.html
> String schemaName = _connection.getSchema();
> Connection jdbcConnection = _connection.getConnection();
> DatabaseMetaData databaseMetaData = jdbcConnection.getMetaData();
> ResultSet resultSet = databaseMetaData.getColumns(null, schemaName,
> tableName, "%");
> Where schemaName is returning null.
That's not good, because when using null, you will get all columns of
all tables (in all schemas) with this table name.
> But the databaseMetadata gives all the columns merged for INFORMATION_SCHEMA.USERS and USERS.
That's what DatabaseMetaData.getColumns is supposed to do (according
to the JDBC API spec) if schemaName is null. It's not a bug (in H2).
> Any idea what to do?
I don't know how to make _connection.getSchema() return the correct
schema name, I guess you need to find out why in DbUnit (I don't know
DbUnit). Basically, schemaName should be "PUBLIC" and not null.
> Are we not allowed creating tables that are named ROLES,
> USERS, or anything inside INFORMATION_SCHEMA.* ?
No. You can't create such a table: "create table
information_schema.users(id int)" fails.
Regards,
Thomas
Hi,I don't know DbUnit, maybe you should ask there. Basically,
_connection.getSchema() needs to return "PUBLIC" and not null. Maybe
setting System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_SCHEMA,
"PUBLIC") will help - I found that here:
http://www.dbunit.org/howto.html
> String schemaName = _connection.getSchema();
> Connection jdbcConnection = _connection.getConnection();
> DatabaseMetaData databaseMetaData = jdbcConnection.getMetaData();
> ResultSet resultSet = databaseMetaData.getColumns(null, schemaName,
> tableName, "%");
> Where schemaName is returning null.That's not good, because when using null, you will get all columns of
all tables (in all schemas) with this table name.
> But the databaseMetadata gives all the columns merged for INFORMATION_SCHEMA.USERS and USERS.
That's what DatabaseMetaData.getColumns is supposed to do (according
to the JDBC API spec) if schemaName is null. It's not a bug (in H2).
> Any idea what to do?
I don't know how to make _connection.getSchema() return the correct
schema name, I guess you need to find out why in DbUnit (I don't know
DbUnit). Basically, schemaName should be "PUBLIC" and not null.> Are we not allowed creating tables that are named ROLES,
> USERS, or anything inside INFORMATION_SCHEMA.* ?No. You can't create such a table: "create table
information_schema.users(id int)" fails.
Regards,
Thomas
>> That's not good, because when using null, you will get all columns of
>> all tables (in all schemas) with this table name.
>
> Thats good to know :) Can we include something like that in the
> documentation, would be helpful for other implementations :)
Well, it's already documented...
> Thanks for this info, I didn't know about the default behavior. If
> schemaName is null, it is not specified, in the past, not specifying the
> schema goes to the default database, maybe it would be nice if a default
> database could be set in H2 (I will check further to see how that is done).
As far as I know, the JDBC specification required that using null
means all schemas. This is how other databases also behave.
> Sorry, I meant the other way around, since there is no default schema in H2,
> we have to place "PUBLIC" infront of tables that have the exact same name as
> the ones in INFORMATION_SCHEMA.
That's not correct. There is a default schema when running SQL
statements, however using null in the DatabaseMetaData call doesn't
use the default schema according to the JDBC specification. The
default schema only applies to running SQL statements. See also:
http://h2database.com/html/grammar.html#set_schema
> Would be nice if the default namespace in H2 is set to PUBLIC instead of
> setting it ourselves everytime.
The default schema doesn't apply to DatabaseMetaData calls per JDBC
specification.
Regards,
Thomas