Fields quetes must be applied in queries to prevent mix reserved words with fields names

Description

Quotes must be appied to fields in queries.
The environment log is:

org.hibernate.cfg.Environment Hibernate 3.2 cr1
org.hibernate.cfg.SettingsFactory RDBMS: MySQL, version: 4.1.16
org.hibernate.cfg.SettingsFactory JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12
org.hibernate.dialect.Dialect Using dialect: org.hibernate.dialect.MySQLDialect

I have an entity, named Group:

@Entity
public class Group {
..
}

But, 'GROUP' is the reserved word of MySQL query language.
Log of hibernate show, that queries is without quotes:

org.hibernate.persister.entity.AbstractEntityPersister Static SQL for entity: org.dicr.isp.entity.Group
org.hibernate.persister.entity.AbstractEntityPersister Version select: select id from Group where id =?
org.hibernate.persister.entity.AbstractEntityPersister Snapshot select: select group_.id, group_.name as name0_, group_.comment as comment0_ from Group group_ where group_.id=?
org.hibernate.persister.entity.AbstractEntityPersister Insert 0: insert into Group (name, comment, id) values (?, ?, ?)
org.hibernate.persister.entity.AbstractEntityPersister Update 0: update Group set name=?, comment=? where id=?
org.hibernate.persister.entity.AbstractEntityPersister Delete 0: delete from Group where id=?
org.hibernate.persister.entity.AbstractEntityPersister Identity insert: insert into Group (name, comment) values (?, ?)

And this make a critical error in program logic:

org.hibernate.tool.hbm2ddl.DatabaseMetadata table not found: Group
ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate Unsuccessful: create table Group (id bigint not null auto_increment, name varchar(255) not null unique, comment varchar(255), primary key (id))
ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Group (id bigint not null auto_increment, name varchar(255) not null unique, com' at line 1
[2006-04-27 23:57:23,895] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate schema update complete

The query: "create table Group (id bigint ..." is not correct.
Must be: "create table `Group` (`id` bigint ..."

Activity

Show:

Steve Ebersole March 21, 2011 at 7:05 PM

Bulk closing stale resolved issues

Igor A Tarasov April 27, 2006 at 11:44 PM

package org.hibernate.dialect.MySQLDialect

public char closeQuote() {
return '`';
}

public char openQuote() {
return '`';
}

quotes MUST be applied to fields in queries by Dialect

Christian Bauer April 27, 2006 at 11:18 PM

Read the documentation, use the forum. Don't open bogus "bug" reports.

Rejected

Details

Assignee

Reporter

Original estimate

Time tracking

No time logged1h remaining

Affects versions

Priority

Created April 27, 2006 at 11:12 PM
Updated March 21, 2011 at 7:05 PM
Resolved April 27, 2006 at 11:18 PM