nordborg wrote:
Adding backticks to your mappings is safe because Hibernate will translate this to the appropriate quote character for the database that you are using.
This makes perfect sense, thanks for the clarification. It would be nice if there was a high-level 'escape' identifiers option that could be set.
Since I am using annotations, I run the following perl script on my Spring/Hibernate DO's and DAO's after generation. This script only backticks identifiers that don't already have them so it's safe to run multiple times.
Code:
#!/usr/bin/perl -w
use strict;
#fixup MyEclipse IDE reversed enginered hibernate 3.2 annotated objects
use Cwd;
# PATH SPEC TO HIBERNATE *.JAVA CLASSES HERE
my $dbDir = '/c/projects/someProject/src/com/bensoft/db';
chdir($dbDir);
# Backquote table and catalog names
system 'perl -pi.orig -e \'s/(\@Table.*name = ")([^`][^"]*)(", catalog = ")([^`][^"]*)(")/$1`$2`$3`$4`$5/g\' *.java';
# Backquote column names
system 'perl -pi.orig -e \'s/(\@Column.*name = ")([^`][^"]*)(")/$1`$2`$3/g\' *.java';
# Remove backup files
system 'rm -r *.orig';
A similar script could be written to handle non-annotation mappings.