rzo1 commented on code in PR #144:
URL: https://github.com/apache/openjpa/pull/144#discussion_r3588337324
##########
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/functions/TestEJBQLFunction.java:
##########
Review Comment:
Thanks for the report — I could reproduce this and tracked it down.
I debugged it with a small standalone `main()` against a fresh in-memory
HSQLDB (`jdbc:hsqldb:mem:x`), just dumping `DatabaseMetaData.getTables` /
`getColumns` output. On a completely empty database:
```
getTables(null, null, "TRANSLATIONS", null)
-> CAT=PUBLIC SCHEM=INFORMATION_SCHEMA NAME=TRANSLATIONS TYPE=SYSTEM TABLE
getColumns(null, null, "TRANSLATIONS", null)
-> 12 rows, all TABLE_SCHEM=INFORMATION_SCHEMA
getColumns(null, "PUBLIC", "TRANSLATIONS", null)
-> (no rows)
```
So the SQL standard defines an information-schema view named `TRANSLATIONS`,
and HSQLDB implements it. Since the test entity maps to
`@Table(name="TRANSLATIONS")` without a schema, OpenJPA's schema reflection
calls `getColumns` with a null schema pattern, gets back the columns of
`INFORMATION_SCHEMA.TRANSLATIONS`, and concludes the table already exists but
is missing the entity columns — hence the `ALTER TABLE TRANSLATIONS ADD COLUMN
id BIGINT` against `PUBLIC`, where no such table exists.
The generic code already has a filter for exactly this
(`DBDictionary.isSystemTable` / `systemSchemaSet`, consulted in
`SchemaGenerator.generateTables`), and the Oracle/Postgres dictionaries use it
— the HSQL dictionary just never registers its system schemas. Maybe something
like this works (in the `HSQLDictionary` constructor):
```java
// HSQLDB reports the tables and views of its system schemas (e.g.
// INFORMATION_SCHEMA.TRANSLATIONS) via DatabaseMetaData when no
// schema is specified; filter them out so they are not mistaken
// for user tables during schema reflection (OPENJPA-2940).
systemSchemaSet.addAll(Arrays.asList(
"INFORMATION_SCHEMA", "SYSTEM_LOBS"
));
```
With that change, `TestTablePerClassInheritanceWithAbstractRoot` (the test
owning the `TRANSLATIONS` entity) passes on `-Ptest-hsqldb`, and the
sequence/generator tests still pass. I also checked the rest of the test suite
for other collisions with HSQLDB's information-schema names — `TRANSLATIONS` is
the only one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]