Alex
Alex

Reputation: 3413

MySQL Case Sensitive in Linux through Hibernate

I moved my development environment in Eclipse from Windows to Debian. When I did that, I noticed that (just some) table names were not being found in MySQL when Hibernate was doing datamodel checks during initialization, due to case-sensitive issues. Two of the tables are still being searched by "Table_name" instead of "table_name". When it occours, Hibernate create new tables "Table_name" ignoring existent "table_name" ones. I read that it is due to a MySQL feature in case-sensitive O.S.

I've added @Table(name="table_name") statement in every model class, in order to avoid capitalization of table names by MySQL/Hibernate, and I reviewed all HQL queries in DAO Classes putting all table references to lower case, but I've not achieved success in either attempts.

What configuration am I missing in order to fix this behavior? Thanks.

Upvotes: 3

Views: 1555

Answers (1)

Mike Nakis
Mike Nakis

Reputation: 61986

This is a well known problem with MySQL because it creates an actual disk file per table.

Hibernate supposedly tries to overcome this problem specifically for MySQL by internally lowercasing all table names, but apparently this is not a bulletproof solution.

As far as I know there is nothing you can do besides making sure that consistent capitalization is used EVERYWHERE. In other words, there is no magic configuration option that will do it for you.

If you use the "hibernate.hbm2ddl.auto" property to let hibernate create your database schema, then you should be fine, but if you are running hibernate on a pre-existing database then this is not enough, because you have to also make sure that the table was created in as 'table_name' and that any foreign key references also refer to it in as 'table_name'. (So, the use of @Table(name="table_name") everywhere will not suffice.)

In either case, your database was created under windows, so even if you had hibernate create it, still it may have been created with whatever funny capitalization scheme you were using under windows, which means that you might want to throw away your database and re-create it.

Upvotes: 2

Related Questions