-->
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: Code generation, column names with spaces
PostPosted: Fri Feb 08, 2008 7:31 am 
Newbie

Joined: Mon Feb 04, 2008 6:31 am
Posts: 8
Hi,
I have a database (either mysql or a &%$# ms access file) and I'm trying to generate Java classes using Hibernate Tools inside Eclipse, and everything's fine except one thing: I have unfortunately column names with spaces inside (e.g. "Some name").
Now the SQL Hibernate generates (from a "from table" query) is

Code:
select ... table.Some name as ... ... from ...


which is obviously wrong (because of the space). I've made a little fix adding the ` to the name attribute:

I have changed the generated:

Code:
@Column(name = "Some name")
public Byte getSomeName() {
    return this.someName;
}


to

Code:
@Column(name = "`Some name`")
public Byte getSomeName() {
    return this.someName;
}


And it works, but I have plenty of tables and plenty of such columns, is there any way to instruct the code generator to do it automatically? I have my own
Code:
public class PemNamingStrategy extends DelegatingReverseEngineeringStrategy { ...


maybe there's a possibility to make this 'fix' there? What am I doing wrong?

If needed, I can paste all the configuration I have, but I do not think it's necessary

--
Regards,
Kornel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 10:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
are you sure you are using the latest ?

AbstractMetaDataDialect has this implementation of needQuote:

Code:
public boolean needQuote(String name) {
      
      if(name==null) return false;
   
      if(name.indexOf('-')>0) return true;
      if(name.indexOf(' ')>0) return true;
      return false;
   }


hence the columns should be escaped automatically.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 7:51 am 
Newbie

Joined: Mon Feb 04, 2008 6:31 am
Posts: 8
I have the latest tools (3.2.0), latest entity manager (3.3.1) and latest hibernate jars (3.2.6).

A quick test:
Code:
   public static void main(String[] args) {
      
      MySQLMetaDataDialect jmd = new MySQLMetaDataDialect();
      System.out.println("Do we need a quote? " + jmd.needQuote("aa bbb"));
      


and yes, it it answers true. So it should quote the names, but it somehow does not. Where should this quote appear, in the @Column(name) property?

What am I doing wrong, I have no idea why it's happening :/


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.