views:

233

answers:

1

Hibernate: I want to have hibernate automatically generate my tables with names in lowercase.

For example, if my class is called com.myapp.domain.Customer, hibernate will generate a table named Customer. I want it to be called customer. I know I can use the @Table annotation to specify the table name per class. But I want it to happen "automagically".

+3  A: 

Isn'it it the job for NamingStrategy?

You would get the name of the entity managed (i.e. Customer) and should decide the table name used (entityName.toLowerCase() in your case).

One thing I am not sure is if the NamingStrategies are taken into account when generating tables (hbm2ddl).

Grzegorz Oledzki
You are right and there is an option to hbm2ddl to specify naming strategy. The particular implementation that you're looking for is `org.hibernate.cfg.ImprovedNamingStrategy`.
Ramon