Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap column names in double quotes in Hibernate

I'm using Spring JPA 2.0.9 with Hibernate 5.3.5 and this dialect to access a FileMaker (v16) database via JDBC using the official JDBC driver taken from this distribution.

The thing is that the resulting SQL ends up being with column names prefixed by the respective table names like:

select 
marketingc0_.a__IDPK_MarketingCategory as a__IDPK_1_0_0_, marketingc0_.Active as Active2_0_0_
from MarketingCategories as marketingc0_
where marketingc0_.a__IDPK_MarketingCategory=1

which FileMaker doesn't accect complaining about the wrong syntax:

[08007][27034] [FileMaker][FileMaker JDBC] FQL0001/(1:153): There is an error in the syntax of the query.

However it gulps down the SQL without complains if the column names are wrapped in double quotes like this:

select
    marketingc0_."a__IDPK_MarketingCategory" as a__IDPK_1_0_0_, marketingc0_."Active" as Active2_0_0_
    from MarketingCategories as marketingc0_
    where marketingc0_.a__IDPK_MarketingCategory=1

The solution I've come up with is including these quotes into the entity annotations:

public class MarketingCategory {
    @Id
    @Column(name = "\"a__IDPK_MarketingCategory\"")
    private Integer id;

    @Column(name = "\"a_ID_User\"")
    private Integer userId;

    @Column(name = "\"Active\"")
    private Boolean active;

...
}

which doesn't look good.

Is it possible configure Hibernate so that it would wrap all the column names in double quotes automatically?

like image 955
super.t Avatar asked Sep 14 '18 09:09

super.t


People also ask

What does double quote means in hibernate?

SQL quoted identifiers. You may force Hibernate to quote an identifier in the generated SQL by enclosing the table or column name in backticks in the mapping document. Hibernate will use the correct quotation style for the SQL Dialect (usually double quotes, but brackets for SQL Server and backticks for MySQL).

What is Spring JPA Hibernate naming implicit strategy?

Implicit Naming Strategy Hibernate uses a logical name to map an entity or attribute name to a table or column name.


1 Answers

You can set a property named hibernate.globally_quoted_identifiers to true in your definitions and it will quote all identifiers. There is an option in addition to that to not quote the columns, but there is no option to only quote the columns.

like image 104
coladict Avatar answered Oct 29 '22 07:10

coladict