-->
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.  [ 4 posts ] 
Author Message
 Post subject: Reserved words in MySQL column names
PostPosted: Fri Jan 11, 2008 9:03 am 
Newbie

Joined: Fri Jan 11, 2008 7:55 am
Posts: 2
Hi,

Just registered because I have observed a weird problem (which presumably has something to do with my configuration).

Hibernate version:
3.2.5.ga


Mapping documents:
Simplets example:
Code:
<class name="FieldDescription" table="FieldDescriptions">
    <property name="key" type="string" />
    <property name="value" type="string" />
</class>


Code between sessionFactory.openSession() and session.close():
Using the HibernateTemplate from Spring:
Code:
FieldDescription fd = new FieldDescription();
fd.setKey("example");
fd.setValue("Example Field");
getHibernateTemplate().merge(fd);


Name and version of the database you are using:
MySQL 5.0.44 (Gentoo Linux patched) on a development laptop.


The generated SQL (show_sql=true):
Code:
insert into FieldDescriptions (key, value) values (?, ?)


Hibernate is set to use the MySQL5InnoDBDialect, but the generated SQL does not escape the key column. The word key is reserved in MySQLs dialect, so a MySQL error is returned stating that there is a syntax-error near: "key, value) values (?, ?)"

Of course I have already worked around this by changing the name "key" to something else as that makes life easier for everyone, but I am still wondering if I've missed something in the configuration? Is there some setting to tell Hibernate to escape the column names?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 9:14 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

seems you're not the only one using reserved words for column-names, since hibernate can handle this. Just look here under "SQL quoted identifiers".

Regards

piet[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 9:22 am 
Newbie

Joined: Fri Jan 11, 2008 7:55 am
Posts: 2
Thanks for the quick reply.. must have missed it in the docs :-)

And yes, I agree that it is a bad idea to use reserved words for column names.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 5:11 am 
Newbie

Joined: Thu Jun 15, 2006 8:32 am
Posts: 6
From the documentation:
Quote:
(usually double quotes, but brackets for SQL Server and backticks for MySQL).


I use annotactions and don't want database specific names in my classes.

I'am facing the same problem with the column "key". Production is running on Postgres and my development environment is running MySql. "key" is not a reserved word on Postgres, but it is on Mysql.

I don't understand why the openQuote form the Dialect isn't used.

Or is there any stetting to force hibernate to use the openQuote and closeQuote?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.