Hibernation naming is different from OS

I ran into the problem that dormant generated schema names (e.g. table names) are different between Windows and Linux. On Windows, all table names are small case, for example. account , while under Linux table names are created - cases of camels, for example. account .

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

 <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's going on here? Basically, I can live with this strange problem, but sometimes itโ€™s annoying, I canโ€™t just export my tables from my Windows IDE to linux.

+6
source share
3 answers

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

+8
source

Unfortunately, this is how mysql works for case sensitive file systems (I had the same problem on a Mac with the "insenstive" file system). To solve this problem, you need to specify a name for the tables yourself.

for instance

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

The table name must be lowercase! Thus, you can be sure that the table will be correctly named MySQL.

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

+5
source

There seemed to be a problem with names or casing.

I changed the following to lowercase and solved the problem:

  • Column names in table (s)
  • Table name
  • I also changed the database name because I used the shotgun approach.
  • All links to the above in the .java and * .hbm.xml files

I did this because I was just starting a project, I wanted to use Hibernate, but I was unfamiliar with it, and I didnโ€™t care if these data-related elements changed.

I also used this approach because it seemed simple and fearless. And if that failed, I would try a different technique and solution.

I did not need to change or add any unfamiliar codes or annotations. All I had to do was omit the following items mentioned above.

This is a basic metadata solution, not an unusual code solution.

This is not elegant, but it removes any ambiguity as to whether the problem with the situation causes your situation.

0
source

Source: https://habr.com/ru/post/889648/


All Articles