openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Zheng (JIRA)" <>
Subject [jira] Commented: (OPENJPA-592) In MySQL explicitly specifying openjpa.jdbc.Schema with default schema gives an error on first time EM access if mapping is already done
Date Tue, 13 May 2008 01:18:55 GMT


Jason Zheng commented on OPENJPA-592:

>>What does mysql return in the table_cat? In the example above, for example, would
the table_cat be "jpa", or something else entirely?
It returns "jpa" for table_cat, and null for table_schem.

Actually these values are set correctly in MySQL information_schema.
mysql> select table_catalog, table_schema from information_schema.columns where table_name='employe
e' and column_name='name';
| table_catalog | table_schema |
| NULL          | jpa          |

It seems to me that the MySQL driver swaps the schema and catalog values.

Please see,137564,137629 for more details. 

>> If we override newColumn in MySQLDictionary to use table_cat instead, don't we need
to make corresponding changes to all these methods? 
Yes, I think so. Actually we have done the same fix for InformixDictionary. InformixDictionary
creates a special field for this problem:

     * Informix JDBC metadata for all known drivers returns with the
     * table catalog and the table schema name swapped. A <code>true</code>
     * value for this property indicates that they should be reversed.
    public boolean swapSchemaAndCatalog = true;

and in newColumn, newPrimaryKey, etc:
if (swapSchemaAndCatalog)


> In MySQL explicitly specifying openjpa.jdbc.Schema with default schema gives an error
on first time EM access if mapping is already done
> ----------------------------------------------------------------------------------------------------------------------------------------
>                 Key: OPENJPA-592
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>            Reporter: Jason Zheng
>         Attachments: patch-592.txt
> Suppose we have an entity "Employee" and we have the following properties specified in
> <property name='openjpa.jdbc.SynchronizeMappings'  value='buildSchema(ForeignKeys=true)'
> <property name='openjpa.jdbc.Schema' value='jpa' />
> OpenJPA  should create table "jpa:employee" if it does not exist in the database, and
do nothing if the table already exists.
> But in MySQL, it tries to create the table when the table already exists in database,
and we will get the following exception because of this:
> <openjpa-1.1.0-SNAPSHOT-r422266:647033 nonfatal general error> 
> org.apache.openjpa.persistence.PersistenceException: Table 'employee' already exists
{stmnt 7294825 CREATE TABLE jpa.employee (id BIGINT NOT NULL, PRIMARY KEY (id)) TYPE = innodb}
[code=1050, state=42S01]
> at  org.apache.openjpa.jdbc.meta.MappingTool.record(
> at org.apache.openjpa.jdbc.meta.MappingTool.record(
> at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(
> ...
> This is because MySQL doesn't have concept of schema, and the column metadata from MySQL
doesn't contain schema information. Hence OpenJPA fails to find the table although the table
exists in database.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message