-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: MySQL backticks
PostPosted: Tue Dec 02, 2008 7:11 pm 
Newbie

Joined: Tue Dec 02, 2008 6:57 pm
Posts: 3
I have been using the MyEclipseIDE to reverse engineer a set of hibernate 3.2 data objects and DAO's using Annotations.

My issue revolves around adding MySQL backticks (`) to table, catalog and column names in order to insure that MySQL queries run properly in situations where names conflict with SQL keywords.

Upon reading the JIRA issue:

http://opensource.atlassian.com/project ... e/HHH-2660

I have taken the course of using a 'fixup' script after object generation to insure that the identifiers are backticked properly.

In HHH-2660 it seems that the developer stance is to add these backticks to the mappings or annotations.

My question is: Should SQL Vendor specific code be added to the mappings this way? This makes the Hibernate mappings configuration non-cross platform!

It seems to me that this should be handled by Hibernate when the MySQLDialect is used.

Any thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2008 4:52 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Adding backticks to your mappings is safe because Hibernate will translate this to the appropriate quote character for the database that you are using. See http://www.hibernate.org/hib_docs/v3/re ... fiers.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2008 5:02 am 
Newbie

Joined: Tue Dec 02, 2008 6:57 pm
Posts: 3
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.