Issue Details (XML | Word | Printable)

Key: HB-409
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Christian Bauer
Reporter: Toni Bennasar Obrador
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Hibernate2

SchemaUpdate fails on MySQL 4.0.11 because table name case sensitivity

Created: 18/Oct/03 05:44 PM   Updated: 13/Aug/04 03:54 AM
Component/s: toolset
Affects Version/s: 2.0.3
Fix Version/s: 3.0 alpha, 2.1.7

Time Tracking:
Not Specified

Environment: Mandrake Linux 9.1 on x86, using MySQL 4.0.11 and official MySQL JDBC v3.0.9 , and Hibernate 2.0.3


 Description  « Hide
Hello. I have the following problems:
I try to do a SchemaUpdate over a MySQL DB over database where the update should add some fields to some table, but the SchemaUpdate try to re-create the table, with <<SQLException>> results...

I did a debug to see what happens and the problem is at net.sf.hibernate.tool.hbm2ddl.DatabaseMetadata at line 47 , where the tool finds if the table exists or not, to create or update the table, :

public TableMetadata getTableMetadata(String name) throws HibernateException {

...

String[] types = {"TABLE"};
ResultSet rs = null;
try {
   try {

THIS>>rs = meta.getTables(null, "%", name.toUpperCase(), types);
      while ( rs.next() ) {
      if ( name.equalsIgnoreCase( rs.getString("TABLE_NAME") ) ) {
         table = new TableMetadata(rs, meta);
         tables.put( name.toUpperCase(), table );
         break;
      }

The line 47 is rs=meta.getTables(null, "%", name.toUpperCase(),Types);
The problem is that hibernate creates the tables (with SchemaExport) with lower case, and MySQL is case sensitive for table names on Unix (see http://www.mysql.com/doc/en/Name_case_sensitivity.html). But the .getTables call finds the upper case table name. Then, never is found, and it try to create the table when it exists.

The fix is remove the .toUpperCase() :
rs = meta.getTables(null, "%", name, types);

or SchemaExport should create the tables with upper case.

Hibernate is great. Thanks for all.




 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Gavin King added a comment - 27/Nov/03 09:21 PM
Christian, you now own SchemaUpdate ;)

Juraci Krohling Costa added a comment - 29/Mar/04 08:24 PM
Actually, Hibernate creates the tables as the hbm.xml. So, if hbm.xml tells that table name is "Animal", Hibernate will create a table named "Animal". If you change "Animal" to "ANIMAL", another table will be created.

To retrieve the tables that is equalsIgnoreCase to the table in hbm.xml, the tablePattern parameter in meta.getTables must be "%". It retrieves ALL tables in the selected database, so, the compare can be done by Hibernate.

But i guess that if MySQL is case sensitive, the user MUST know that and remove manually the old tables. Otherwise, Hibernate can remove wrong table, removing user's data.

CVS Notification Service added a comment - 13/Aug/04 03:43 AM
CVS COMMIT LOG:
SUBJECT: [Hibernate-commits] Hibernate3/src/org/hibernate/tool/hbm2ddl ColumnMetadata.java,1.1,1.2 DatabaseMetadata.java,1.1,1.2 ForeignKeyMetadata.java,1.1,1.2 IndexMetadata.java,1.1,1.2 TableMetadata.java,1.1,1.2
fixed problems with SchemaUpdate (after all this time)
HB-478, HB-409


CVS Notification Service added a comment - 13/Aug/04 03:43 AM
CVS COMMIT LOG:
SUBJECT: [Hibernate-commits] Hibernate3/src/org/hibernate/cfg Configuration.java,1.18,1.19
fixed problems with SchemaUpdate (after all this time)
HB-478, HB-409


Gavin King added a comment - 13/Aug/04 03:50 AM
Fixed

CVS Notification Service added a comment - 13/Aug/04 03:54 AM
CVS COMMIT LOG:
SUBJECT: [Hibernate-commits] Hibernate3/src/org/hibernate/tool/hbm2ddl DatabaseMetadata.java,1.2,1.3
fixed problems with SchemaUpdate (after all this time)
HB-478, HB-409


CVS Notification Service added a comment - 13/Aug/04 03:54 AM
CVS COMMIT LOG:
SUBJECT: [Hibernate-commits] Hibernate2/src/net/sf/hibernate/cfg Configuration.java,1.35,1.36
fixed problems with SchemaUpdate (after all this time)
HB-478, HB-409, HB-1159


CVS Notification Service added a comment - 13/Aug/04 03:54 AM
CVS COMMIT LOG:
SUBJECT: [Hibernate-commits] Hibernate2/src/net/sf/hibernate/tool/hbm2ddl ColumnMetadata.java,1.4,1.5 DatabaseMetadata.java,1.4,1.5 ForeignKeyMetadata.java,1.4,1.5 IndexMetadata.java,1.4,1.5 TableMetadata.java,1.6,1.7
fixed problems with SchemaUpdate (after all this time)
HB-478, HB-409, HB-1159


CVS Notification Service added a comment - 13/Aug/04 03:54 AM
CVS COMMIT LOG:
SUBJECT: [Hibernate-commits] Hibernate2/src/net/sf/hibernate/tool/hbm2ddl DatabaseMetadata.java,1.5,1.6
fixed problems with SchemaUpdate (after all this time)
HB-478, HB-409, HB-1159


CVS Notification Service added a comment - 13/Aug/04 03:54 AM
CVS COMMIT LOG:
SUBJECT: [Hibernate-commits] Hibernate3/src/org/hibernate/tool/hbm2ddl DatabaseMetadata.java,1.3,1.4
fixed problems with SchemaUpdate (after all this time)
HB-478, HB-409