6

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.

2
  • 1
    Do you specify the names on tables and columns or do you let hibernate pick a name for you? I'm quite sure that this happens because the windows file system is not case sensitive and linux is. This affects mysql as each table name ends up being a file. For example, in linux you can have all the following tables in a schema: test, Test and tEst, while in windows that would cause an error (table already exist).
    – Augusto
    Jun 3, 2011 at 9:54
  • I leave the naming of the tables up to Hibernate
    – Erik
    Jun 3, 2011 at 12:20

3 Answers 3

8

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

1
  • Thanks for sharing that gouki, I didn't know about that feature.
    – Augusto
    Jun 3, 2011 at 19:16
5

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.

2
  • 1
    I had all these annotations before, but I think it's bad design to put them if you want to let Hibernate create all the stuff. Is there a way to provide some kind of a "Hibernate Naming Scheme"?
    – Erik
    Jun 3, 2011 at 15:19
  • 1
    Please don't tell a DBA that you're letting hibernate create the schema or he might have some kind of violent reaction :).
    – Augusto
    Jun 3, 2011 at 19:15
0

It seemed clear there was a naming or casing problem.

I changed the following to lower-case, and it solved the problem:

  1. Column-names in the table(s)
  2. Table name(s)
  3. I also changed the database name, because I used the shotgun approach.
  4. All references to the above in the .java and *.hbm.xml file(s)

I did this because I was just starting a project, wanted to use Hibernate but was unfamiliar with it, and did not care if these data-related items changed ever so slightly.

I also took this approach because it seemed straightforward and unmysterious. And if it failed, I would try a different technique and solution.

I didn't have to change or add any unfamiliar code or annotation. All I had to do was to lower-case the items mentioned above.

It's a basic meta-data solution, rather than an unfamiliar code solution.

It's inelegant, but it removes any ambiguity concerning whether a case-related problem is causing your situation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.