Hibernate version: latest (trunk) in subversion
Mapping documents: using annotation-based configuration
Name and version of the database you are using: mysql 5, innodb
Debug level Hibernate log excerpt:
Code:
18 Jul 2008 11:35:30 ERROR [hbm2ddl.SchemaUpdate] - Unsuccessful: create table forum_category (id bigint not null auto_increment, description varchar(255), hidden bit not null, name varchar(255), order integer not null, primary key (id)) ENGINE=InnoDB
18 Jul 2008 11:35:30 ERROR [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 'order integer not null, primary key (id)) ENGINE=InnoDB' at line 1
we are trying to use annotation based config with hibernate, avoiding the use of @Column wherever necessary. here is the relevant java code in the domain object.
Code:
@Entity
@Table(name = "forum_category")
public class Category {
...etc...
private int order = 0;
...etc...
/**
* @return the order
*/
public int getOrder() {
return order;
}
/**
* @param order
* the order to set
*/
public void setOrder(int order) {
this.order = order;
}
}
obviously, the word 'order' is a reserved word in mysql, which is causing a problem. if we were using XML based configuration, then we'd simply surround the column name with backticks (`) which would cause Dialect.quote() to add db-specific quotes.
i can see no logical reason why we WOULDN'T want to add backticks to all column names (for example, it's just one additional level of security against sql injection attacks). however, because Dialect.quote() is final, i cannot override the chosen dialect (MySQL5InnoDBDialect) with one that automatically quotes everything like this :
Code:
public final String quote(String column) {
if ( column.charAt( 0 ) == '`' ) {
return openQuote() + column.substring( 1, column.length() - 1 ) + closeQuote();
} else {
return openQuote() + column + closeQuote();
}
}
is there any reason why a) quoting backticks aren't added automatically regardless, and b) we can't override Dialect.quote() to provide this functionality in a custom dialect? as i mentioned, using annotation-based configuration, this means we need to add a @Column(name="`order`") directive to each reserved word, which is terribly annoying.
thanks for any help and assistance :)