- This topic has 2 replies, 1 voice, and was last updated 16 years, 1 month ago by dbennett455.
-
AuthorPosts
-
dbennett455ParticipantI would like to modify the Hibernate Reverse Engineering templates to backtick all table and column references to fix compatibility issues between Hibernate and MySQL. I am using Hibernate 3.2 Annotations so I would like to change the Abstract data object POJO’s generation from:
@Column(name = "key", nullable = false, length = 2) public String getKey() { return this.key; }
To:
// backticks around column name @Column(name = "`key`", nullable = false, length = 2) public String getKey() { return this.key; }
I have copied the velocity templates from com.genuitec.eclipse.hibernate_6.6.0.zmyeclipse660200810/templates into the project, but I can’t see where the annotation code is exposed in the templates.
Granted this should be handled by Hibernate like all of the MySQL utilities do, however, the Hibernate team keeps closing the issue whenever anyone brings this up saying ‘add the backticks to your mappings’. This would work, except in the case of reverse engineering where you are overwriting your mappings and you loose the backticks.
Is is possible to modify Hibernate Reverse Engineering to do this?
dbennett455ParticipantAssuming this is going to be difficult, I wrote a perl script to do the work. This will edit the source files in place and only update table, catalog and column references that are not already backticked. (i.e. it’s safe to run multiple times)
#!/usr/bin/perl -w use strict; #fixup MyEclipse IDE reversed enginered hibernate 3.2 annotated objects use Cwd; my $dbDir='{insert directory to your generated objects here}';; 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';
dbennett455ParticipantAfter reading this section in the documentation:
http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping-quotedidentifiers.html
It appears that the backtick quotes are treated in a cross-platform way by Hibernate. I would recommend that quoting identifiers be added as a feature to the MyEclipse Hibernate Reverse engineering tool.
-
AuthorPosts