Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate scheme naming differs between OS

I am facing the problem that the hibernate generated schema names (table names for example) differ between Windows and Linux. On Windows all table names are small case, e.g. account, whereas under Linux created table names are camel cases, e.g. Account.

On both systems I use MySQL 5 in the same version and the following hibernate config:

<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<prop key="hibernate.bytecode.provider">cglib</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop> 

What happens here? Basically I can live with that weird issue, but sometimes its annoying I cannot just export my tables from my windows IDE to my linux environment.

like image 351
Erik Avatar asked Jun 02 '11 18:06

Erik


2 Answers

You might want to set the property hibernate.ejb.naming_strategy to org.hibernate.cfg.ImprovedNamingStrategy or implement your own naming strategy class.

like image 125
gouki Avatar answered Sep 21 '22 00:09

gouki


Unfortunately, this is the way mysql works on case sensitive file systems (I had the same problem on Mac with the case "insenstive" filesystem). To solve this problem, you'll need to provide the name for the tables yourself.

For example

@Entity
@Table(name="user")
public class User implements Serializable {
    ...
}

The table name should be all in lower case! In this way, you can be sure that the table will be named properly by MySQL.

Jut to be very clear, the problem is not hibernate, but how mysql handles table names.

like image 5
Augusto Avatar answered Sep 23 '22 00:09

Augusto