-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Exception with hbm2ddl.auto=update on MySQL
PostPosted: Sat Dec 17, 2005 7:20 am 
Newbie

Joined: Sat Dec 17, 2005 6:40 am
Posts: 4
Hi all,

I'm using Hibernate 3.0.5 to store data into MySQL 5.0.16. The tables are created in database 'jsp' (lowercase) via hbm2ddl.auto=update - on the first run, with empty DB everything works fine. However on any subsequent run Hibernate tries to read and eventually update the schema, but using upercase(!) database name 'JSP'. With most other DB engines this probably is not a problem, but MySQL is case sensitive and therefore database 'jsp' != 'JSP'.

Although schema update doesn't work the connection pool is created OK using lowercase DB name and the application continues as expected (unless the schema changes, of course).

The workaround is obviously using uppercase database name, then it works fine. But sometimes this isn't possible.

Is the described behaviour a bug or did I miss some config option somewhere?

Versions:
Hibernate 3.0.5, MySQL 5.0.16, MySQL J/Connector 3.1.11

Mapping documents:
hibernate.cfg.xml:
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://rumburak/jsp</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>

Full stack trace of any exception that occurs:
Code:
Dec 17, 2005 11:27:15 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1049, SQLState: 42000
Dec 17, 2005 11:27:15 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Unknown database 'JSP'
Dec 17, 2005 11:27:15 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: could not complete schema update
org.hibernate.exception.JDBCConnectionException: could not get table metadata: USERS
        at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:67)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
        at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(DatabaseMetadata.java:94)
        at org.hibernate.cfg.Configuration.generateSchemaUpdateScript(Configuration.java:744)
        at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:135)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:265)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
        at logix.HibernateUtil.<clinit>(HibernateUtil.java:21)
        at logix.User.save(User.java:56)
        at logix.Main.main_hibernate(Main.java:11)
        at logix.Main.main(Main.java:68)
Caused by: java.sql.SQLException: Unknown database 'JSP'
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
        at com.mysql.jdbc.Statement.executeQuery(Statement.java:822)
        at com.mysql.jdbc.DatabaseMetaData$9.forEach(DatabaseMetaData.java:4453)
        at com.mysql.jdbc.DatabaseMetaData$IterateBlock.doForAll(DatabaseMetaData.java:79)
        at com.mysql.jdbc.DatabaseMetaData.getTables(DatabaseMetaData.java:4440)
        at com.mysql.jdbc.DatabaseMetaData$2.forEach(DatabaseMetaData.java:1928)
        at com.mysql.jdbc.DatabaseMetaData$IterateBlock.doForAll(DatabaseMetaData.java:79)
        at com.mysql.jdbc.DatabaseMetaData.getColumns(DatabaseMetaData.java:1894)
        at org.hibernate.tool.hbm2ddl.TableMetadata.initColumns(TableMetadata.java:173)
        at org.hibernate.tool.hbm2ddl.TableMetadata.<init>(TableMetadata.java:33)
        at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(DatabaseMetadata.java:79)
        ... 8 more
Dec 17, 2005 11:27:15 PM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://rumburak/jsp?useUnicode=true&characterEncoding=UTF-8


Name and version of the database you are using:
MySQL 5.0.16, MySQL J/Connector 3.1.11


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 8:14 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
I used mysql, and don't have this problem.

I think your mapping files should give the table name as lowercase instead of uppercase and then it would work.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 18, 2005 3:46 am 
Newbie

Joined: Sat Dec 17, 2005 6:40 am
Posts: 4
anar wrote:
I think your mapping files should give the table name as lowercase instead of uppercase and then it would work.


This is not a problem with table names but with a database name. Table names work fine both in lowercase and uppercase, but when having a database name in lowercase, subsequent hbm2ddl update will wrongly try to use it in uppercase and therefore doesn't find it and fails.

Just for completeness I tried to change the table names to lowercase but it didn't help at all. The only solution I have found so far is having the database name in uppercase, but that isn't always possible.


Top
 Profile  
 
 Post subject: This is a bug in MySQL JDBC driver
PostPosted: Sun Dec 18, 2005 5:20 am 
Newbie

Joined: Sat Dec 17, 2005 6:40 am
Posts: 4
After some more hours of debugging and subsequent googling it turns out that the problem is in MySQL Connector/J 3.1.11 that wrongly reports

Code:
DatabaseMetaData.storesUpperCaseIdentifiers()==true


Apparently fixed in MySQL Connector/J 3.1.12 (just tested).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 18, 2005 5:23 am 
Newbie

Joined: Thu Oct 20, 2005 8:30 am
Posts: 10
Have you already created the database jsp?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 18, 2005 5:32 am 
Newbie

Joined: Sat Dec 17, 2005 6:40 am
Posts: 4
feryshirano wrote:
Have you already created the database jsp?


Heh, yeah I did, I'm not that dumb ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.