-->
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.  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Database independant Column/Table name escaping?
PostPosted: Fri Jan 28, 2005 10:01 am 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Hibernate version:
2.1.7

Name and version of the database you are using:
MySQL 4.0
MSSQL 2000

Hello everyone,

When mapping a column/table which name is a reserved keyword (of the database server), you have to use escapes like '' (MySQL) or [] (MSSQL) in the mapping descriptors (e.g. column="[index]").

Unfortunately, these escape characters are dependant on the database server. Is there any way to stay database independant and let the Dialect do the escaping?

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 10:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use backticks in the mapping file


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 10:22 am 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Thanks for your help.

I think this only solves part of the problem. How should I know which names are reserved keywords (those are database server dependant, are they?)? I would need to escape each table/column name in the descriptor just to be on the safe side. Couldn't this be done by some Hibernate configuration?

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 12:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, escape everything. There is currently no option to do this automatically.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
one could use a NamingStrategy for this i presume ,)

it could just quote whatever is not quoted.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 12:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hmm, good idea yes ... I should read my own blog articles more often :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 28, 2005 11:42 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 2:21 pm
Posts: 20
Location: Toronto
michael wrote:
Yes, escape everything. There is currently no option to do this automatically.

It is a bad advice.
I use hbm2java to generate my pogo, now you see that it simply produce :
Code:
get'Key'()

I think that implementation for a specific database should escape fields if needed.

I am using Hibernate3 with MySQL, but in Hibernate2 it was all right, fields has been escaped.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 2:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it only produces that if you put quotes in your property name which you should never do. the quotes goes in the column name!

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 3:47 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 2:21 pm
Posts: 20
Location: Toronto
max wrote:
it only produces that if you put quotes in your property name which you should never do. the quotes goes in the column name!
-max

I define only property names to ensure that DB colum mapped to a property with a same name.
When you have a few developers someone will misspell property name and instead of `center` I will get `centre`.

B.t.w. does this issue has been reported in JIRA, I can't find anything related there ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 4:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
did you read the thread and tried to use namingstrategy to apply quoting transparently ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 4:59 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 2:21 pm
Posts: 20
Location: Toronto
Yes, I read the thread, this why I am posting here.
I am not using NamingStrategy.
If I would try to do some tricks and default implementation wouldn't allow me to do so, I would use NamingStrategy to find my way.
But I am talking about an obvious bug in MySQL dialect.
A simple generated SQL won't work :
Code:
insert into my_table (key) values ('my_key_value');

My conclusion is that MySQL dialect implementation should escape field names, to comply with:
http://dev.mysql.com/doc/mysql/en/reserved-words.html


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 5:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i don't understand ?!

If NamingStrategy can solve your problem why don't you use it ?

You can implement a NamingStrategy that obeys the url you just posted.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 5:20 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 2:21 pm
Posts: 20
Location: Toronto
Newer mind, users who find this topic will figure out that you can't rely on implementation provided.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 5:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
huh ? we explicit state that quoting is the job for the user.

And if you think about it and investigate a bit you will see its almost impossible to make this work in the dialect since databases has different reserved keywords and different need/semantics for quoting....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 5:35 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 2:21 pm
Posts: 20
Location: Toronto
Oh yes, before posting here, I check the source and how other people solve the problem.

But I can't see why MySQL dialect can't take care for reserved words that specific to MySQL database ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 25 posts ]  Go to page 1, 2  Next

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.