[CONJ-193] No escape of reserved words in hibernate calls Created: 2015-09-08  Updated: 2015-10-26  Resolved: 2015-10-26

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.2.0
Fix Version/s: 1.2.3

Type: Bug Priority: Major
Reporter: Stefan Assignee: Diego Dupin
Resolution: Not a Bug Votes: 0
Labels: Hibernate
Environment:

Win7 but I thing the problem is on all platforms, mariadb 10, hibernate 3



 Description   

I've to use tables with reserved words in mariadb.
Here is an example:
CREATE BASE TABLE t1(
`table` VARCHAR(20),
)ENGINE=InnoDB;

If I try to insert data into this table using the Hibernate persist function:
@Transactional(readOnly = false)
public T add(final T t) {
this.getEntityManager().persist(t);
this.getEntityManager().flush();
return t;
}

MariaDB throws a "systax error".

Reason is, that the reserved word is not escaped in the resulting hibernate request !

This is the generated request:
sql : 'insert into t1 ( table) values ', parameters: ['myt']

A correct request should look like this (with escaped attribute table):
sql : 'insert into t1 ( `table` ) values ', parameters: ['myt']

I'm not 100% sure, but I think the implementation org.hibernate.dialect is responsible for database specific implementations and should escape the reserved words.

I specified the dialect this way by using MYSQL, because there is no seperate MARIADB dialect.

<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="showSql" value="true" />
<property name="database" value="MYSQL" />
</bean>
</property>



 Comments   
Comment by Diego Dupin [ 2015-10-26 ]

table is a reserved word in MariaDB/MySQL databases.
so it must be escaped.
Hibernate has a property for that since version 3.5: globally_quoted_identifiers
you have to add
<property name="hibernate.globally_quoted_identifiers" value="true"/>
or
<property name="globally_quoted_identifiers" value="true"/>
depending if your type of configuration.

Generated at Thu Feb 08 03:13:52 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.