I had solved this problem as follows:
I had create following class:
import org.hibernate.cfg.DefaultNamingStrategy;
public class MysqlAdvancedNamingStrategy extends DefaultNamingStrategy{
@Override
public String columnName(String columnName) {
return "`"+super.columnName(columnName)+"`";
}
@Override
public String tableName(String tableName) {
return "`"+super.tableName(tableName)+"`";
}
}
I had setting as namingStrategy the "MysqlAdvancedNamingStrategy" at previous point.
The advantages of this solution is that you don't need to modify all annotation in you code.
It is also a clean solution because for some reason you may want have an application that access to same database "logic" in two different "database" (so with two style of escaping), with this solution you can intercept what database are you using and you can change the escaping strategy at "execution time", however the annotation are evalutated at "compilation time".
It is also a clean solution if you use Spring framework, with this you can change the escaping strategy without touching java code by setting a bean in session factory with id="namingStrategy" and class="util.MysqlAdvancedNamingStrategy".